Drag and Drop

Kayot

Well-known member
Joined
Mar 6, 2007
Messages
49
Programming Experience
3-5
^-^ After last times folly (Never figured threads out, too bad to. Moving on) I have a new question. I am making a custom control. I've been making it for several days now. That aside, I decided I wanted to embed Drag and Drop rather than to have to put it on every form and set up a control array which was time consuming and generally annoying. I hit my head figuring out how to pass the object to another object, in this case a custom PictureBox. I got it to work after I figured out I was a noob. Now heres the new problem. It copys fine. And thats the problem. I want it to move the data. And since I'm bringing it up I wanted to add some short cut keys. Due to its PictureBox Nature, it generally ignores keys, not sure why.

What I want is to use the Control Key to run the clear command I made. It's a sub, so nothing fancy. Then I wanted to use Shift to activate the copy (That happens already, but I want to stop it.) I know thats a lot to ask, but after all these days, I'm sure I'm the problem.

VB.NET:
Private Sub Slot_MouseDown(ByVal sender As Object, _
	ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

	If e.Button = Windows.Forms.MouseButtons.Left Then
		If Me.ItemID = 0 And Me.SpellID = 0 Then
		Else
			If e.Button = Windows.Forms.MouseButtons.Left = True Then
				Me.DoDragDrop(Me, DragDropEffects.Move)
			End If
		End If
	End If
End Sub

Private Sub Slot_DragEnter(ByVal sender As Object, _ 
	ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter

	If e.Data.GetDataPresent(GetType(imgInventorySlot)) = True Then
		e.Effect = DragDropEffects.Move
	Else
		e.Effect = DragDropEffects.None
	End If
End Sub

Private Sub Slot_DragDrop(ByVal sender As Object, _ 
	ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

	Dim imgItem As imgInventorySlot = DirectCast(e.Data.GetData(GetType(imgInventorySlot)), imgInventorySlot)
	If e.Data.GetDataPresent(GetType(imgInventorySlot)) = True Then
		Me.Image = imgItem.Image
	End If
End Sub

It took me quite some time to write this, feel free to use it in your own program. A few notes, this is on a Class that inherits the PictureBox. I can post the whole class if it helps. I need to know how to access the first object, and because the object can't use external variables it has to do it another way. I have no clue how to do that. Or the shortcut keys which would make my life so much easer.

Things I've Tried:
  • Attempted to put a me.image = nothing in MouseDown, clicking it kills the image. Not good.
  • Put it in the Drag Drop for sender, killed the image in the new box.
  • Attempted to call the first box, generally failed. I didn't fail to make it work. I just found 20 or so ways to make it not work.

So any help would be much abisjhed. I hope this isn't asking too much.
 
Back
Top