I have a usercontrol named groupControl: It has two flowlayoutpanel - source panel and destination panel. It also has a button.
I have another usercontrol named item. I will dynamically lay N item controls in source panel and M item controls in target panel.
I want there are straight lines between each item control and button on groupControl.
Finally I have a test form MainForm, it also contains a flowlayoutpanel. I will dynamically lay X groupcontrols on MainForm.
How could I draw straight lines between each usercontrol item and the button on the same groupControl?
The Visual Basic Power Pack contains a DataRepeater, and some shapes (oval, rectangle..) including a line. See this link.
It is called "Visual Basic" Power Pack, but it can be used in a C# project without any hassle.
Look at the DataRepeater, not only it will help you to fill your panel with custom controls as items, but it contains what you need to put a line between them.
You'd have to edit something like this to fit your correct Start and End Points (pt1
and pt2
), but...
FlowLayoutPanel flowLayoutPanel1;
FlowLayoutPanel flowLayoutPanel2;
private void ShippingForm_Paint(object sender, PaintEventArgs e) {
using (Graphics g = e.Graphics) {
Point pt1 = flowLayoutPanel1.Location;
Point pt2 = flowLayoutPanel2.Location;
using (Pen p = new Pen(Brushes.Black)) {
g.DrawLine(p, pt1, pt2);
}
}
}
EDIT:
If you have a form called ShippingForm
(like I did above), go to the form's event handlers in the GUI and add double click on the Pant
event to generate the empty method stub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With