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. Dragging the panel on the form

Dragging the panel on the form

Scheduled Pinned Locked Moved C#
9 Posts 3 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
    Sokka93
    wrote on last edited by
    #1

    Here is the code. I hope it works for you.

    private Point mousePos;
    private Point panelPos;
    private bool isDragging;

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    isDragging = true;
    Cursor.Current = Cursors.Hand;
    mousePos = panel1.PointToScreen(e.Location);
    panelPos = panel1.Location;
    }

    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
    if(isDragging)
    {
    isDragging = false;
    Cursor.Current = Cursors.Default;
    }
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
    if (!isDragging) return;
    Point point = panel1.PointToScreen(e.Location);
    panel1.Left = panelPos.X + point.X - mousePos.X;
    panel1.Top = panelPos.Y + point.Y - mousePos.Y;
    }

    P 1 Reply Last reply
    0
    • S Sokka93

      Here is the code. I hope it works for you.

      private Point mousePos;
      private Point panelPos;
      private bool isDragging;

      private void panel1_MouseDown(object sender, MouseEventArgs e)
      {
      if(e.Button == MouseButtons.Left)
      {
      isDragging = true;
      Cursor.Current = Cursors.Hand;
      mousePos = panel1.PointToScreen(e.Location);
      panelPos = panel1.Location;
      }

      }

      private void panel1_MouseUp(object sender, MouseEventArgs e)
      {
      if(isDragging)
      {
      isDragging = false;
      Cursor.Current = Cursors.Default;
      }
      }

      private void panel1_MouseMove(object sender, MouseEventArgs e)
      {
      if (!isDragging) return;
      Point point = panel1.PointToScreen(e.Location);
      panel1.Left = panelPos.X + point.X - mousePos.X;
      panel1.Top = panelPos.Y + point.Y - mousePos.Y;
      }

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      Thanks, but is there a problem or what?

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

      S 1 Reply Last reply
      0
      • P Paul Conrad

        Thanks, but is there a problem or what?

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

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

        there is no problem I just wanted to share it with you. :)

        P N 2 Replies Last reply
        0
        • S Sokka93

          there is no problem I just wanted to share it with you. :)

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          That's cool. How about you write a quick little beginner article on it. As simple as it is, some folks might find it helpful :-D

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

          S 1 Reply Last reply
          0
          • P Paul Conrad

            That's cool. How about you write a quick little beginner article on it. As simple as it is, some folks might find it helpful :-D

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

            S Offline
            S Offline
            Sokka93
            wrote on last edited by
            #5

            I don't know.

            P 1 Reply Last reply
            0
            • S Sokka93

              I don't know.

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              Ummm, you don't know what?

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              S 1 Reply Last reply
              0
              • P Paul Conrad

                Ummm, you don't know what?

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                S Offline
                S Offline
                Sokka93
                wrote on last edited by
                #7

                I don't know that I can write an article,because I'm working on a project for Infomatrix. How about you? I guess you're a Software Developer.

                P 1 Reply Last reply
                0
                • S Sokka93

                  I don't know that I can write an article,because I'm working on a project for Infomatrix. How about you? I guess you're a Software Developer.

                  P Offline
                  P Offline
                  Paul Conrad
                  wrote on last edited by
                  #8

                  Furkan93 wrote:

                  How about you?

                  Could just add it to the never ending list to todo :rolleyes:

                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                  1 Reply Last reply
                  0
                  • S Sokka93

                    there is no problem I just wanted to share it with you. :)

                    N Offline
                    N Offline
                    netJP12L
                    wrote on last edited by
                    #9

                    what does this code code ....upload a picture

                    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