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. connecting labels on a panel with lines

connecting labels on a panel with lines

Scheduled Pinned Locked Moved C#
questiondatabasehelp
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.
  • D Offline
    D Offline
    dfn
    wrote on last edited by
    #1

    Hi. I have an app that reads the DB, and then populates a panel in my program with a bunch of labels. The user is able to drag those labels anywhere on the panel (basically drag and drop, using MouseDown, MouseMove, MouseUp). Some of those labels have "links" between them which I'd like to represent with lines, connecting one label to another. I'd also like the lines to be redrawn to the new label location once a label is moved by a user. What is the easiest way to do this? I tried maintaining a list of labels and their links, and updating the link, then just redrawing lines. However, in my MouseUp function, where the links are updated (mouse up means the user "dropped" the label and so it has a new location), the x,y coords of e are always zero: [pre] private void my_lbl_MouseUp(object sender, MouseEventArgs e) { drag = false; Point temp; for (int i = 0; i < Links.Count; i++ ) { if (Links[i].p1 == old_point1 || Links[i].p1 == old_point2) { Links[i].p1.X += e.X; Links[i].p1.Y += e.Y; } if (Links[i].p2 == old_point1 || Links[i].p2 == old_point2) { Links[i].p2.X += e.X; Links[i].p2.Y += e.Y; } } } [/pre] Can anyone tell me why e.X and e.Y are always zero when a user moves the labels? Or an easier way to do what I've described above? Any help or advice is appreciated.

    D C 2 Replies Last reply
    0
    • D dfn

      Hi. I have an app that reads the DB, and then populates a panel in my program with a bunch of labels. The user is able to drag those labels anywhere on the panel (basically drag and drop, using MouseDown, MouseMove, MouseUp). Some of those labels have "links" between them which I'd like to represent with lines, connecting one label to another. I'd also like the lines to be redrawn to the new label location once a label is moved by a user. What is the easiest way to do this? I tried maintaining a list of labels and their links, and updating the link, then just redrawing lines. However, in my MouseUp function, where the links are updated (mouse up means the user "dropped" the label and so it has a new location), the x,y coords of e are always zero: [pre] private void my_lbl_MouseUp(object sender, MouseEventArgs e) { drag = false; Point temp; for (int i = 0; i < Links.Count; i++ ) { if (Links[i].p1 == old_point1 || Links[i].p1 == old_point2) { Links[i].p1.X += e.X; Links[i].p1.Y += e.Y; } if (Links[i].p2 == old_point1 || Links[i].p2 == old_point2) { Links[i].p2.X += e.X; Links[i].p2.Y += e.Y; } } } [/pre] Can anyone tell me why e.X and e.Y are always zero when a user moves the labels? Or an easier way to do what I've described above? Any help or advice is appreciated.

      D Offline
      D Offline
      dfn
      wrote on last edited by
      #2

      oops, sorry:

          private void my\_lbl\_MouseUp(object sender, MouseEventArgs e)
          {
              drag = false;
              Point temp;
      
              for (int i = 0; i < Links.Count; i++)
              {
                  if (Links\[i\].p1 == old\_point1 || Links\[i\].p1 == old\_point2)
                  {
                      Links\[i\].p1.X += e.X;
                      Links\[i\].p1.Y += e.Y;
                  }
      
                  if (Links\[i\].p2 == old\_point1 || Links\[i\].p2 == old\_point2)
                  {
                      Links\[i\].p2.X += e.X;
                      Links\[i\].p2.Y += e.Y;
                  }
              }
          }
      
      1 Reply Last reply
      0
      • D dfn

        Hi. I have an app that reads the DB, and then populates a panel in my program with a bunch of labels. The user is able to drag those labels anywhere on the panel (basically drag and drop, using MouseDown, MouseMove, MouseUp). Some of those labels have "links" between them which I'd like to represent with lines, connecting one label to another. I'd also like the lines to be redrawn to the new label location once a label is moved by a user. What is the easiest way to do this? I tried maintaining a list of labels and their links, and updating the link, then just redrawing lines. However, in my MouseUp function, where the links are updated (mouse up means the user "dropped" the label and so it has a new location), the x,y coords of e are always zero: [pre] private void my_lbl_MouseUp(object sender, MouseEventArgs e) { drag = false; Point temp; for (int i = 0; i < Links.Count; i++ ) { if (Links[i].p1 == old_point1 || Links[i].p1 == old_point2) { Links[i].p1.X += e.X; Links[i].p1.Y += e.Y; } if (Links[i].p2 == old_point1 || Links[i].p2 == old_point2) { Links[i].p2.X += e.X; Links[i].p2.Y += e.Y; } } } [/pre] Can anyone tell me why e.X and e.Y are always zero when a user moves the labels? Or an easier way to do what I've described above? Any help or advice is appreciated.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I don't know why the arguments in the event args would be broken, but what if you just store the current position in the mouse move ? In any case, if I am dragging something, I'd expect to update the position in the mouse move event, so I can call invalidate and have the object drawn as it's being moved.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        D 1 Reply Last reply
        0
        • C Christian Graus

          I don't know why the arguments in the event args would be broken, but what if you just store the current position in the mouse move ? In any case, if I am dragging something, I'd expect to update the position in the mouse move event, so I can call invalidate and have the object drawn as it's being moved.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          D Offline
          D Offline
          dfn
          wrote on last edited by
          #4

          Thank you! I don't know why it doesn't work in MouseUp, but having it redraw during movement (in MouseMove) works. Well, kinda, but I have the main problem solved. Thanks again for your help!

          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