Hi, I need help , I to want know how i can make a button move, to some position to another position, the position have to be where I want, please help me. In case Im working in c# Microsoft Visual Studio. Thanks
ps: send ansewer to: aerodeslizador@hotmail.com
thanks pls help me

Help please windows application Visual Studio
ezhxra
Private blnMoving As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
Private Sub TV_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
If e.Button = MouseButtons.Left Then
blnMoving = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub TV_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp
If e.Button = MouseButtons.Left Then
blnMoving = False
End If
End Sub
Private Sub TV_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseMove
If blnMoving Then
Dim temp As Point = New Point()
temp.X = Button1.Location.X + (e.X - MouseDownX)
temp.Y = Button1.Location.Y + (e.Y - MouseDownY)
Button1.Location = temp
End If
End Sub
krog
I assume you are looking to move a control at runtime. Here is some code to help with that:
private const int WM_SYSCOMMAND = 0x112; private const int MOUSE_MOVE = 0xF012; private const int WM_NCLBUTTONDOWN = 0xA1; private const int HTCAPTION = 2;
[
DllImport("user32")] public static extern int ReleaseCapture(IntPtr hwnd);[
DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); public Form1(){
InitializeComponent();
this.textBox1.MouseDown +=new MouseEventHandler(control_MouseDown); this.button1.MouseDown += new MouseEventHandler(control_MouseDown);}
private void control_MouseDown(object sender, MouseEventArgs e){
if (e.Button == MouseButtons.Left){
Control control = sender as Control;ReleaseCapture(control.Handle);
SendMessage(control.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
simserob
BTN.Location = New point(X,y)
hipolito
I have a further problem related to this.
I use the code in the above message, but with the addition of an option to Snap To Grid.
This is done my only moving the object to the nearest grid position when the mouse reaches it.
Unfortunately, if the control is small, or you click on it near an edge, the mouse moves off the control because the control only moves when you reach a grid point. Consequently, the MouseMove events go to whatever is behind it.
As the things behind it may also be draggable objects, it makes their MouseMove event handlers complicated because they have to detect whether it is themself that's being moved.
Is there an easier way