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