Moving a control with the mouse
-
Hi, I'm implementing a drag object operation with panels. The code i'm using for that is:
private void panel_MouseDown(object sender, MouseEventArgs e) { Panel region = (Panel)sender; drag = true; panelBeingMoved = region; x = e.X; y = e.Y; } private void panel_MouseUp(object sender, MouseEventArgs e) { drag = false; panelBeingMoved = null; } private void panel_MouseMove(object sender, MouseEventArgs e) { if (drag) { panelBeingMoved.Left += e.X + x; panelBeingMoved.Top += e.Y -y; x = e.X; y = e.Y; } }
The problem is that the panel behaves in a very strange way. Instead of coming togheter smoothly with the mouse it is always jumping around with some pattern that i can justify. Is there any simple explanation for this bahaviour? What am i missing? Thx, Nuno -
Hi, I'm implementing a drag object operation with panels. The code i'm using for that is:
private void panel_MouseDown(object sender, MouseEventArgs e) { Panel region = (Panel)sender; drag = true; panelBeingMoved = region; x = e.X; y = e.Y; } private void panel_MouseUp(object sender, MouseEventArgs e) { drag = false; panelBeingMoved = null; } private void panel_MouseMove(object sender, MouseEventArgs e) { if (drag) { panelBeingMoved.Left += e.X + x; panelBeingMoved.Top += e.Y -y; x = e.X; y = e.Y; } }
The problem is that the panel behaves in a very strange way. Instead of coming togheter smoothly with the mouse it is always jumping around with some pattern that i can justify. Is there any simple explanation for this bahaviour? What am i missing? Thx, NunoHi this is a different , method to move Control hope it will help , Class1.cs
using System; using System.Runtime.InteropServices; public class Class1 { public static int HTCAPTION = 2; public static int WM_NCLBUTTONDOWN = 0xA1; [DllImport("user32.dll")] public static extern int ReleaseCapture () ; [DllImport("user32.dll")] public static extern int SendMessage (IntPtr hWnd, int wMsg , int wParam, ref int lParam ) ; public Class1() { } }
Example :private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { int reflParam = 0; Class1.ReleaseCapture (); Class1.SendMessage (panel1.Handle , Class1.WM_NCLBUTTONDOWN , Class1.HTCAPTION , ref reflParam ); }
P.S JUST TRY IT ... it's work like charming even if it look dos not Have a good day ....I know nothing , I know nothing
-
Hi this is a different , method to move Control hope it will help , Class1.cs
using System; using System.Runtime.InteropServices; public class Class1 { public static int HTCAPTION = 2; public static int WM_NCLBUTTONDOWN = 0xA1; [DllImport("user32.dll")] public static extern int ReleaseCapture () ; [DllImport("user32.dll")] public static extern int SendMessage (IntPtr hWnd, int wMsg , int wParam, ref int lParam ) ; public Class1() { } }
Example :private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { int reflParam = 0; Class1.ReleaseCapture (); Class1.SendMessage (panel1.Handle , Class1.WM_NCLBUTTONDOWN , Class1.HTCAPTION , ref reflParam ); }
P.S JUST TRY IT ... it's work like charming even if it look dos not Have a good day ....I know nothing , I know nothing
Hi, Yes, this solution worka like charms. The only problem is that i don't understand what i am doing. How can i get reference documentation for this? How can i know what more can i do with this? I would love to be able to resize for example. Like you do when you choose a transform operation in Photoshop for example. Thx, Nuno
-
Hi, Yes, this solution worka like charms. The only problem is that i don't understand what i am doing. How can i get reference documentation for this? How can i know what more can i do with this? I would love to be able to resize for example. Like you do when you choose a transform operation in Photoshop for example. Thx, Nuno
hi ( and thank you for testing my code ;) ) no worries , if you don't understand it ... cause my code was C++ and Win32 API , more than C# code you can find many of this stuff , by searching in ( MSDN , Win32 API , C++ code .... etc ) have a good day :)
I know nothing , I know nothing