Click here to Skip to main content
15,908,274 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi

Icant drwing line by start/end point

can u help me for

drwing line by start/end point ?


Thanks ! [Email address removed]
Posted
Updated 2-Jun-13 7:25am
v2
Comments
Thomas Daniels 2-Jun-13 13:27pm    
Never post your email address in a public forum, if you don't like spam!
Read here why: http://ask-leo.com/why_shouldnt_i_post_my_email_address_in_a_public_forum.html

1 solution

Hi,

If you use Windows Forms, then use the Graphics.DrawLine method:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawline.aspx[^]
You can draw a line on your Form in the Paint event[^]:
C#
// in constructor
public Form1()
{
    InitializeComponent();
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
// Form1_Paint event handler:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    Graphics g = e.Graphics;
    g.DrawLine(Pens.Black, x1, y1, x2, y2);
}

If you use WPF, then use System.Windows.Shapes.Line:
http://msdn.microsoft.com/en-us/library/system.windows.shapes.line.aspx[^]
http://msdn.microsoft.com/en-us/library/ms742122.aspx[^]

[Edit]Error fixed[/Edit]
 
Share this answer
 
v2
Comments
Member 10000548 3-Jun-13 0:59am    
Ihave two error at this Solution 1:
Error 1 'System.Windows.Forms.PaintEventHandler' is a 'type', which is not valid in the given context c:\users\user\documents\Projects\line by startend\line by startend\Form1.cs 17 27 line by startend
Error 2 'line_by_startend.Form1' does not contain a definition for 'Form1_Paint' and no extension method 'Form1_Paint' accepting a first argument of type 'line_by_startend.Form1' could be found (are you missing a using directive or an assembly reference?) c:\users\user\documents\Projects\line by startend\line by startend\Form1.cs 17 71 line by startend
Thomas Daniels 3-Jun-13 11:25am    
I fixed the error, and I updated my answer (I forgot the <small>new</small> keyword)

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