Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. Can I save the lines that I'll draw? Coz I was thinking of making a reference to the lines I created.

2. I have a picturebox that was connected to another picturebox using a line. (Just like a flowchart, but the lines are in "Z" shape). Is it possible that when I moved my picturebox in runtime, lines will follow? My pictureboxes are movable. If yes, please tell me how.


Here my code in Paint Event:
C#
void PaintThis(object sender, PaintEventArgs e)
 {

     newStruct ST = new newStruct();

     xd.Load(filename);
     XmlNodeList xnl = xd.SelectSingleNode("root").ChildNodes;



     foreach (XmlNode xn in xnl)
     {


         XmlElement xe = (XmlElement)xn;
         XmlNodeList name = xe.GetElementsByTagName("picname");
         XmlNodeList x1 = xe.GetElementsByTagName("x1");
         XmlNodeList y1 = xe.GetElementsByTagName("y1");
         XmlNodeList xc = xe.GetElementsByTagName("xcenter");
         XmlNodeList yc = xe.GetElementsByTagName("ycenter");
         XmlNodeList x2 = xe.GetElementsByTagName("x2");
         XmlNodeList y2 = xe.GetElementsByTagName("y2");

         ST.graps = e.Graphics;
         Pen myPen = new Pen(System.Drawing.Color.Blue, 3);


         for (int j = 0; j < name.Count; j++)
         {

             ST.x1St = Convert.ToInt32(x1[j].InnerText);
             ST.y1St = Convert.ToInt32(y1[j].InnerText);
             ST.xcSt = Convert.ToInt32(xcenter[j].InnerText);
             ST.ycSt = Convert.ToInt32(ycenter[j].InnerText);
             ST.x2St = Convert.ToInt32(x2[j].InnerText);
             ST.y2St = Convert.ToInt32(y2[j].InnerText);
             ST.halfHeight = 50;
             ST.halfWidth = 50;


             //DRAW LINES IN PANEL THROUGH POINTS
             ST.graps.DrawLine(myPen, ST.x1St + ST.halfWidth, ST.y1St + ST.halfHeight, ST.xcSt, ST.ycSt + ST.halfHeight);
             ST.graps.DrawLine(myPen, ST.xcSt, ST.ycSt + ST.halfHeight, ST.xcSt, ST.x2St);
             ST.graps.DrawLine(myPen, ST.xcSt, ST.x2St, ST.x2St, ST.y2St);

         }
     }
 }


Thanks.:confused:
Posted
Updated 1-Feb-11 0:13am
v2
Comments
shakil0304003 1-Feb-11 5:08am    
Please, share your code!!!
yummy02 1-Feb-11 5:19am    
Here my code in Paint Event:

void PaintThis(object sender, PaintEventArgs e)
{

newStruct ST = new newStruct();

xd.Load(filename);
XmlNodeList xnl = xd.SelectSingleNode("root").ChildNodes;



foreach (XmlNode xn in xnl)
{


XmlElement xe = (XmlElement)xn;
XmlNodeList name = xe.GetElementsByTagName("picname");
XmlNodeList x1 = xe.GetElementsByTagName("x1");
XmlNodeList y1 = xe.GetElementsByTagName("y1");
XmlNodeList xc = xe.GetElementsByTagName("xcenter");
XmlNodeList yc = xe.GetElementsByTagName("ycenter");
XmlNodeList x2 = xe.GetElementsByTagName("x2");
XmlNodeList y2 = xe.GetElementsByTagName("y2");

ST.graps = e.Graphics;
Pen myPen = new Pen(System.Drawing.Color.Blue, 3);


for (int j = 0; j < name.Count; j++)
{

ST.x1St = Convert.ToInt32(x1[j].InnerText);
ST.y1St = Convert.ToInt32(y1[j].InnerText);
ST.xcSt = Convert.ToInt32(xcenter[j].InnerText);
ST.ycSt = Convert.ToInt32(ycenter[j].InnerText);
ST.x2St = Convert.ToInt32(x2[j].InnerText);
ST.y2St = Convert.ToInt32(y2[j].InnerText);
ST.halfHeight = 50;
ST.halfWidth = 50;


//DRAW LINES IN PANEL THROUGH POINTS
ST.graps.DrawLine(myPen, ST.x1St + ST.halfWidth, ST.y1St + ST.halfHeight, ST.xcSt, ST.ycSt + ST.halfHeight);
ST.graps.DrawLine(myPen, ST.xcSt, ST.ycSt + ST.halfHeight, ST.xcSt, ST.x2St);
ST.graps.DrawLine(myPen, ST.xcSt, ST.x2St, ST.x2St, ST.y2St);

}
}
}
Estys 1-Feb-11 5:35am    
It would be better to update your question with the code and add a reply to the comment of shakil, that way he will be notified.
yummy02 1-Feb-11 6:49am    
Thanks for editing/updating my questions. :)

1 solution

If you have UI elements that are movable then you will need to respond to the event that handles the completion of the move (or the in-progress movement).

When that happens, you need to call the code that draws the lines. You should be able to invalidate the drawing surface or invoke the appropriate refresh method on your drawing surface.

Cheers.
 
Share this answer
 
Comments
yummy02 3-Feb-11 21:46pm    
Thanks :) But Some lines also disappear when I redraw new lines. How can I redraw specific lines and retain others that wasn't move yet by the user. I mean If I have to move specific picturebox, the line connected to this one follow, but the other lines not connected to it remains.

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