How to move the CommandButton control using mouse from one position to other?

  • Thread starter Sakharam Phapale
  • Start date
S

Sakharam Phapale

Hi All,

How to move the CommandButton control using mouse from one position to
other?
Is it possible using Drag, Drop events or I have to write my own code for
that?

I have set the "AllowDrop" property to true. But when I try to drag the
Button it doesn't move.
Any help will be appreciated.

Thanks and Regards
Sakharam Phapale
 
P

Peter Proost

This should do it

<<<<<<code>>>>>>

Private dragging As Boolean
Private beginX, beginY As Integer

Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

dragging = True
beginX = e.X
beginY = e.Y

End Sub

Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If dragging = True Then
Button2.Location = New Point(Button2.Location.X + e.X -
beginX,Button2.Location.Y + e.Y - beginY)
Me.Refresh()
End If
End Sub

Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp

dragging = False

End Sub


<<<<<<code>>>>>>>


hth Peter
 
S

Sakharam Phapale

Hi Peter,

Thanks for your reply.

I want to use Drag and Drop events.
Any idea?

Thanks and regards
Sakharam Phapale
 
P

Peter Proost

Hi Sakharam,

Drag drop is used for dragging and dropping data (for example from one
listbox to another) it doesn't move a control, you have to write your own
code to move a control like for example the code I posted.

Greetz Peter
 
O

One Handed Man \( OHM - Terry Burns \)

He wants to use the DoDragDrop methods of the the Controls he wants to move.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
C

Cor Ligthert

Terry,

I know, however the answer from Peter is in my opinion very good and very
efficient, so why botter to do it in a more difficult way?

I once saw in this newsgroup somebody fighting to do it with the drag and
drop while the method from Peter is so easy. (I would have given an answer
as that when Peter had not done that)

I even do not know if it is possible with drag and drop.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top