3 Replies - 1191 Views - Last Post: 02 October 2009 - 11:04 AM Rate Topic: -----

#1 ace_w1zard  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 02-October 09

Does any body know how to make a click and drag interface in vb.08

Post icon  Posted 02 October 2009 - 01:31 AM

Hey guys i did some research on click and drag and i still dont get it, can any body plz help me with this.

P.S. when i write in the code i ALWAYS get a not defined error!
Is This A Good Question/Topic? 0
  • +

Replies To: Does any body know how to make a click and drag interface in vb.08

#2 ace_w1zard  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 02-October 09

Re: Does any body know how to make a click and drag interface in vb.08

Posted 02 October 2009 - 01:42 AM

[quote name='ace_w1zard' date='2 Oct, 2009 - 12:31 AM' post='786287']
Hey guys i did some research on click and drag and i still dont get it, can any body plz help me with this.

P.S. when i write in the code i ALWAYS get a not defined error!
Public Class Form1
	Dim HoldLeft As Integer
	Dim HoldTop As Integer

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

	End Sub

	Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
		Go = True

	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
		' Check if the mouse is down
		If Go = True Then


			HoldLeft = (Control.MousePosition.X - Me.Left)
			HoldTop = (Control.MousePosition.Y - Me.Top)

			If TopSet = False Then
				OffTop = HoldTop - sender.Top
				
				TopSet = True
			End If
			If LeftSet = False Then
				OffLeft = HoldLeft - sender.Left
			
				LeftSet = True
			End If


			sender.Left = HoldLeft - OffLeft
			sender.Top = HoldTop - OffTop
		End If

	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
		Go = False
		LeftSet = False
		TopSet = False

	End Sub
End Class



tht is my code, know why do i have 13 not declared errors
Was This Post Helpful? 0
  • +
  • -

#3 ace_w1zard  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 02-October 09

Re: Does any body know how to make a click and drag interface in vb.08

Posted 02 October 2009 - 09:47 AM

can anybody plz help me!!!
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Does any body know how to make a click and drag interface in vb.08

Posted 02 October 2009 - 11:04 AM

Well, to start with, you will need to use the Drag/Drop events for the controls in question.

For example:

Create a new form and on that form add a label

Change the Label Text to something like: This can be dragged

Add a TextBox and set the AllowDrop property to True

Then use this code:

	Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
		Label1.DoDragDrop(Label1.Text, DragDropEffects.Copy)
	End Sub

	Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
		TextBox1.Text = e.Data.GetData(DataFormats.Text).ToString
	End Sub

	Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
		If e.Data.GetDataPresent(DataFormats.Text) Then
			' There is text. Allow copy.
			e.Effect = DragDropEffects.Copy
		Else
			' There is no text. Prohibit drop.
			e.Effect = DragDropEffects.None
		End If
	End Sub



So in the mousedown event of the label I begin the drag of the text and I am only copying it.

When I drag it to the textbox which has code for DragEnter I check to make sure I'm actually dragging something and if so, the DragDrop event puts that text into the textbox.


Now click and hold the label and drag it inside the textbox and release the mouse button.
This should be enough to play around with and see what is going on. I'm not an expert in this area but I know enough to create a reason to pull more hair out of my head ;)

This post has been edited by CharlieMay: 02 October 2009 - 11:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1