Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
3.50/5 (3 votes)
See more:
C#
List<Point> points = new List<Point>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
            if (e.Button == MouseButtons.Left)
            {
                points.Add(e.Location);
                pictureBox1.Invalidate();
               
            }
}

C#
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
             if (points.Count > 1)
                e.Graphics.DrawLines(Pens.Magenta, points.ToArray());
}

I have been drawing lines, curves, ...I have the button: btnDrawLine, btnDrawCurve
Each button press will call a function to draw.When you press the button, an item be added to the listbox.
For example:click btnDrawLine-> "combobox" add Line.
The user can move the line or curve by selecting the name in the listbox.
How do I do this?
thank.I will put an object (line, Curve) into a PictureBox.
How to a PictureBox always display when other PictureBox override it?
Posted
Updated 13-Jan-12 23:27pm
v3

1 solution

This is simple: don't use PictureBox. This is a common mistake to use this control for the functionality where it presents much more hassles then help compared to the custom control derived from System.Windows.Forms.Control.

You can find more detailed explanations in my past answers:
How do I clear a panel from old drawing[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^].

After reading some of my answers references above you will know exactly what to do.

—SA
 
Share this answer
 
Comments
giatuan2011 14-Jan-12 4:23am    
I have an idea.
If I put an object as lines, rectangles into a PictureBox, I think it would be simpler.Then I just use Cotrols.Add to add PictureBox and move the PictureBox contains objects when user want to move line/Curve.
But I get a problem.That is the size of the PictureBox will change when clicking drawing.how to the transparent PictureBox background to the object behind don't lost?
Toli Cuturicu 14-Jan-12 9:40am    
SAKryukov has already told you NOT to use a PictureBox for that purpose and he is RIGHT. So, why are you still asking him about PictureBoxes then?
Sergey Alexandrovich Kryukov 14-Jan-12 12:25pm    
Thank you, Toli. OP is asking about the problem which is a good illustration of the misuse of the PictureBox.
--SA
Sergey Alexandrovich Kryukov 14-Jan-12 12:23pm    
It is not simpler. If you don't trust me, do whatever you want, but deal with this problem by yourself. This problem is yet another illustration of what I say. If you do it right, this problem simply does not exist.
--SA

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