Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace projetodetestes
- {
- public partial class testedragdrop : Form
- {
- public testedragdrop()
- {
- InitializeComponent();
- }
- private void testedragdrop_Load(object sender, EventArgs e)
- {
- listBox1.AllowDrop = true;
- }
- private void listBox1_MouseDown(object sender, MouseEventArgs e)
- {
- if (this.listBox1.SelectedItem == null) return;
- this.listBox1.DoDragDrop(this.listBox1.SelectedItem, DragDropEffects.Move);
- }
- private void listBox1_DragOver(object sender, DragEventArgs e)
- {
- e.Effect = DragDropEffects.Move;
- }
- private void listBox1_DragDrop(object sender, DragEventArgs e)
- {
- Point point = listBox1.PointToClient(new Point(e.X, e.Y));
- int index = this.listBox1.IndexFromPoint(point);
- if (index < 0) index = this.listBox1.Items.Count - 1;
- object data = listBox1.SelectedItem;
- this.listBox1.Items.Remove(data);
- this.listBox1.Items.Insert(index, data);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement