Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, I have a user control that has picture boxes. Those picture boxes are added according as to how many pictures are saved in xml file. Meaning to say, My user control loads the content of my xml file. Now that I can load the picture boxes by means of creating instances, my goal now is to create a line that connects specific picture boxes.

For example, the pbox 1 connects to pbox 5 and pbox 3. That's it. Do I have to user the paint event? or is there any codes available. Help me.

Pointers will be appreciated, Thanks :)
Sergey Alexandrovich Kryukov 27-Dec-10 21:43pm    
System.Windows.Forms or WPF?!!
Dr.Walt Fair, PE 27-Dec-10 21:52pm    
In WinForms you can use the DrawLine method.
Sergey Alexandrovich Kryukov 27-Dec-10 23:11pm    
You're right, Walt; and for WPF this is not a problem at all; for example, all object on Canvas are 1st-class citizen.

Yep, you will need to hook into the Paint event and add logic to to draw the lines onto the Graphics object that is passed into it through the PaintEventArgs. Here's an example, but you will need to change it to draw the lines that you need:
private void Form1_Paint ( object sender, PaintEventArgs e )
     Graphics g = e.Graphics;

     Point point_from = new Point ( x1, y1 );
     Point point_to = new Point ( x2, y2 );

     g.DrawLine ( Pens.Black, point_from, point_to );
Share this answer
yummy02 27-Dec-10 21:53pm    
Thanks JOAT-MON. By the way, what's with point_from and point_to?
JOAT-MON 27-Dec-10 22:01pm    
Just miscellaneous variable names for points to use in the can use any name you want to. I used those for the example to show the direction of the line drawing. They represent the endpoints of the line you want to draw.
Dalek Dave 27-Dec-10 23:10pm    
Good Answer
yummy02 28-Dec-10 2:19am    
by the way, can I create an instance of lines that will connect pictureboxes?
JOAT-MON 28-Dec-10 13:45pm    
What you will be creating are a series of lines that look like they connect PictureBoxes. So the coordinates you assign to the endpoints when you draw the lines should be on the border of the PictureBoxes that you want to connect.
See here[^] as well.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900