Jason Huang wrote:
Hi,
In my C# Windows Form, how do I draw a Line?
Thanks for help.
Jason
You can do all sorts of things... the straight forward way is to use
Graphics.DrawLine. You can get the Form's graphic object by doing
something like this (I'm not checking my code, so it might be slightly
different than this):
Graphics.FromHnd( this.Handle )
then you can quickly draw a line straight from that
Graphics.FromHnd( this.Handle ).DrawLine( args to draw line with )
I'm not sure if getting a graphics object in this way requires you to
also dispose of it - if that's the case you may want to do:
using ( Graphics g = Graphics.FromHnd( this.Handle ) )
{
g.DrawLine( args to draw line with );
}
but like I said, i'm not 100% sure...
Play around with that...
For super easy lines, if you want a straight line (Horiz or Vert), you
can make a panel, change it's background color to the color you would
like the line to be, and then adjust it's width and height.