Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Moving a control with the mouse

Moving a control with the mouse

Scheduled Pinned Locked Moved C#
regexhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sinosoidal
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • S sinosoidal

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • L Lost User

        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

        S Offline
        S Offline
        sinosoidal
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • S sinosoidal

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups