I new to c# and I am struggling to draw a line in a form. Here is the code I have so far.
Graphics g;
g = this.CreateGraphics();
Pen myPen = new Pen(Color.Red);
myPen.Width = 30;
g.DrawLine(myPen, 30, 30, 45, 65);
g.DrawLine(myPen, 1, 1, 45, 65);
Try it in OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g;
g = e.Graphics;
Pen myPen = new Pen(Color.Red);
myPen.Width = 30;
g.DrawLine(myPen, 30, 30, 45, 65);
g.DrawLine(myPen, 1, 1, 45, 65);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With