Creating an application that is able to drag and drop
Hey, I am trying to create and application that has a section on the left of the form that has about 8-10 smallish images in it. The user can then drag the images one at a time from the box of images and create his own model/diagram.
can you guys point me in the right direction on how to implement this? I am going to be doing more with the application, but I need to just start by accomplishing this. Thanks
Re: Creating an application that is able to drag and drop
Take a look at the link in JMCs signature. He posted a thread in the codebank that covers lots of aspects of drag and drop. It's a good place to start when getting into the subject. Aside from that, I think we would probably need much more information to be able to suggest anything useful. For instance, are the images all the same size? Is the target area a grid, or can the items be placed arbitrarily? And so on.
Re: Creating an application that is able to drag and drop
Okay, I got my application to be able to drag and drop from one picture box to another, But how about from a picture box to just anywhere in my "drawing area"? Also, what control should I use? I am thinking of just a panel, or groupbox? Here is the code for picture box 2 that allows an item to be dropped there. But for me, I need my images to be dropped in a groupbox or panel (unless there are better ideas), how can I modify it to be able to drop any picture anywhere in my drawing area?
Code:
Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
' Assign the image to the PictureBox.
PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)
' If the CTRL key is not pressed, delete the source picture.
If Not e.KeyState = 8 Then
PictureBox1.Image = Nothing
End If
Re: Creating an application that is able to drag and drop
I get 6 errors that all look similar to this.
Error 1 Unable to open module file 'C:\Users\Nick\AppData\Local\Temp\Temp2_dragdrop images.zip\dragdrop images\Form1.Designer.vb': The system cannot find the file specified. C:\Users\Nick\AppData\Local\Temp\Temp2_dragdrop images.zip\dragdrop images\Form1.Designer.vb 1 1 dragdrop images
Re: Creating an application that is able to drag and drop
Holy cow, almost all of that is way over my head! Is that the easiest way? One more thing, once the picture is dropped in panel, you can't move it again. What is the easiest way to correct that?
Re: Creating an application that is able to drag and drop
Thanks, but now I need to let thew user add information about each picture in the drawing. I need the user to double click an image and then a form(?) pops up and has a 3-5 text boxes so that the user can add info about that picture. However, when I add a inputbox to an images doubleclick, or mouse double click event, nothing happens when I double click the image either after I have dragged and dropped it, or before. Do you know why this is? Also since the user needs to be able to add more than one piece of info about each image, is the best thing to do is to have a form pop up with multiple text boxes? Or is there a way to have an input box with more than one textbox??
Private Sub PictureBoxes_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
'show your custom dialog
End Sub
So do I need both of these? I tried the second method and it did not work. So is what you are saying is that you need to add the first method to be able to do the second method?
Private Sub PictureBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DoubleClick
MessageBox.Show("HEy")
End Sub
Thinking that maybe I could do each picturebox separately, but the method I tried isn't working either. Any other ideas?
Private Sub PictureBoxes_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragOver, PictureBox2.DragOver, PictureBox3.DragOver, PictureBox4.DragOver, PictureBox5.DragOver, PictureBox6.DragOver, PictureBox7.DragOver, PictureBox8.DragOver, Panel1.DragOver
'make sure drag drop data can be used
If e.Data.GetDataPresent(DataFormats.Bitmap) And e.AllowedEffect = DragDropEffects.Move Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Dim source As PictureBox
Dim image As Bitmap
Private Sub PictureBoxes_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, PictureBox5.MouseDown, PictureBox6.MouseDown, PictureBox7.MouseDown, PictureBox8.MouseDown
source = DirectCast(sender, PictureBox)
If Environment.TickCount - CInt(source.Tag) < GetDoubleClickTime Then
MsgBox("heyhey")
End If
source.Tag = Environment.TickCount
image = DirectCast(source.Image.Clone, Bitmap)
source.DoDragDrop(image, DragDropEffects.Move)
End Sub
Public Sub PictureBoxes_giveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles PictureBox1.GiveFeedback, PictureBox2.GiveFeedback, PictureBox3.GiveFeedback, PictureBox4.GiveFeedback, PictureBox5.GiveFeedback, PictureBox6.GiveFeedback, PictureBox7.GiveFeedback, PictureBox8.GiveFeedback, Panel1.GiveFeedback
e.UseDefaultCursors = False
Dim EffectCursor As New Cursor(New IO.MemoryStream(My.Resources.Move))
Dim img As New Bitmap(15 + image.Width, 26 + image.Height)
Re: Creating an application that is able to drag and drop
Okay now, in your opinion, can you tell me what would be the best way to collect like 5 pieces of data from each picture dropped? I was thinking of when you double click a image, a new form opens up with the appropriate number of text boxes that the user needs to enter the data into. Is there a better option for doing this? I tried searching google but didn't find much because I didn't know really what to search for!