Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace projetodetestes
  5. {
  6. public partial class testedragdrop : Form
  7. {
  8. public testedragdrop()
  9. {
  10. InitializeComponent();
  11. }
  12.  
  13. private void testedragdrop_Load(object sender, EventArgs e)
  14. {
  15. listBox1.AllowDrop = true;
  16. }
  17.  
  18. private void listBox1_MouseDown(object sender, MouseEventArgs e)
  19. {
  20. if (this.listBox1.SelectedItem == null) return;
  21. this.listBox1.DoDragDrop(this.listBox1.SelectedItem, DragDropEffects.Move);
  22. }
  23.  
  24. private void listBox1_DragOver(object sender, DragEventArgs e)
  25. {
  26. e.Effect = DragDropEffects.Move;
  27. }
  28.  
  29. private void listBox1_DragDrop(object sender, DragEventArgs e)
  30. {
  31. Point point = listBox1.PointToClient(new Point(e.X, e.Y));
  32. int index = this.listBox1.IndexFromPoint(point);
  33. if (index < 0) index = this.listBox1.Items.Count - 1;
  34. object data = listBox1.SelectedItem;
  35. this.listBox1.Items.Remove(data);
  36. this.listBox1.Items.Insert(index, data);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement