Click to See Complete Forum and Search --> : drag and drop issue


techker
January 19th, 2010, 02:17 PM
hey guys i have a little app that shows pictures from the program directory .

now i set up a group box with multiple picture boxes .my goal is to take the pic in the main picture box and drag it to the groupe box so i can print that group box after im done.It for a workout program im doing..

here is my code

Public Class Image_list1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents PictureBox4 As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox3 As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Image_list1))
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Button1 = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button4 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.PictureBox4 = New System.Windows.Forms.PictureBox
Me.PictureBox3 = New System.Windows.Forms.PictureBox
Me.PictureBox2 = New System.Windows.Forms.PictureBox
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox1.SuspendLayout()
CType(Me.PictureBox4, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.PictureBox3, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'ImageList1
'
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
Me.ImageList1.Images.SetKeyName(0, "")
Me.ImageList1.Images.SetKeyName(1, "")
Me.ImageList1.Images.SetKeyName(2, "")
Me.ImageList1.Images.SetKeyName(3, "")
Me.ImageList1.Images.SetKeyName(4, "")
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(126, 12)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(170, 185)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(25, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Next"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Button4)
Me.GroupBox1.Controls.Add(Me.Button3)
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.PictureBox4)
Me.GroupBox1.Controls.Add(Me.PictureBox3)
Me.GroupBox1.Controls.Add(Me.PictureBox2)
Me.GroupBox1.Location = New System.Drawing.Point(13, 217)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(678, 212)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "GroupBox1"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(634, 167)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(44, 23)
Me.Button4.TabIndex = 5
Me.Button4.Text = "Clear"
Me.Button4.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(413, 167)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(44, 23)
Me.Button3.TabIndex = 4
Me.Button3.Text = "Clear"
Me.Button3.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(184, 167)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(49, 23)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Clear"
Me.Button2.UseVisualStyleBackColor = True
'
'PictureBox4
'
Me.PictureBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.PictureBox4.Location = New System.Drawing.Point(462, 28)
Me.PictureBox4.Name = "PictureBox4"
Me.PictureBox4.Size = New System.Drawing.Size(164, 163)
Me.PictureBox4.TabIndex = 2
Me.PictureBox4.TabStop = False
'
'PictureBox3
'
Me.PictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.PictureBox3.Location = New System.Drawing.Point(239, 27)
Me.PictureBox3.Name = "PictureBox3"
Me.PictureBox3.Size = New System.Drawing.Size(167, 163)
Me.PictureBox3.TabIndex = 1
Me.PictureBox3.TabStop = False
'
'PictureBox2
'
Me.PictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.PictureBox2.Location = New System.Drawing.Point(12, 28)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(165, 163)
Me.PictureBox2.TabIndex = 0
Me.PictureBox2.TabStop = False
'
'Image_list1
'
Me.AllowDrop = True
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
Me.ClientSize = New System.Drawing.Size(703, 441)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.PictureBox1)
Me.Name = "Image_list1"
Me.Text = "Image_list1"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox1.ResumeLayout(False)
CType(Me.PictureBox4, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.PictureBox3, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region
Dim count As Integer = 0

Private Sub ImageList1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit
PictureBox1.Image = ImageList1.Images.Item(count)
PictureBox1.Height = Me.Height - 100
PictureBox1.Width = Me.Width - 100

PictureBox1.AllowDrop = True
PictureBox2.AllowDrop = True
PictureBox3.AllowDrop = True
PictureBox4.AllowDrop = True
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
PictureBox1.Image = ImageList1.Images.Item(count)

End Sub

Private Sub ImageList1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel

count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
PictureBox1.Image = ImageList1.Images.Item(count)

End Sub


Private Sub Button1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown

count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
PictureBox1.Image = ImageList1.Images.Item(count)
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

End Sub

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

End Sub

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
Dim picstr() As String
Dim str As String

If e.Data.GetDataPresent(DataFormats.FileDrop) Then
picstr = e.Data.GetData(DataFormats.FileDrop)
str = picstr(0)
PictureBox2.ImageLocation = str
End If
End Sub

Private Sub PictureBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
e.Effect = e.AllowedEffect
End Sub

Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click

End Sub

Private Sub PictureBox3_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox3.DragDrop
Dim picstr() As String
Dim str As String
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
picstr = e.Data.GetData(DataFormats.FileDrop)
str = picstr(0)
PictureBox3.ImageLocation = str
End If
End Sub

Private Sub PictureBox3_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox3.DragEnter
e.Effect = e.AllowedEffect
End Sub

Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click

End Sub

Private Sub PictureBox4_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox4.DragDrop
Dim picstr() As String
Dim str As String
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
picstr = e.Data.GetData(DataFormats.FileDrop)
str = picstr(0)
PictureBox4.ImageLocation = str
End If
End Sub

Private Sub PictureBox4_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox4.DragEnter
e.Effect = e.AllowedEffect
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox2.Image = Nothing
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PictureBox3.Image = Nothing
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
PictureBox4.Image = Nothing
End Sub

Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
Dim picstr() As String
Dim str As String
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
picstr = e.Data.GetData(DataFormats.FileDrop)
str = picstr(0)
PictureBox1.ImageLocation = str
End If
End Sub
End Class


The only thing that works now is to take an outside pic and drag it to the form..thx!

Skizmo
January 19th, 2010, 02:27 PM
Your code is Visual Basic, not C++. You are in the wrong place.

cilu
January 19th, 2010, 02:59 PM
[ redirected ]

Cimperiali
January 24th, 2010, 03:40 PM
You added code to drag drop from external to form. You now would like to drag drop a picture fcrom inside the form to a picturebox below. Thus you are not dragging a file, but an image.
Under the main picture, you should write code to handle mosue down + left button clicked (=user is dragging from there to somewhere). Something like:

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy)
End If
End Sub

Once the user drop over a picturebox below, you should handle whait is coming as image, not as the name of a file. something like:

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop


If e.Data.GetDataPresent(DataFormats.Bitmap) Then
PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)

End If
End Sub