Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click a button - draw a Rectangle.

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
This should be simple but I'm missing something. :(
I need a simple example whereby I click a button and draw a rectangle on the form.
The problem I have is that I only seem to understand how to do Graphics work as part of the form's Paint event as this makes use of the System.Windows.Forms.PaintEventArgs.
How can I achieve the above outside the scope of the form's Paint event code.
Any help / pointers would be appreciated.
Thanks in advance.
Steve
 
System.Drawing.Pen p1 = new System.Drawing.Pen(Color.Black, 2);
Graphics g = this.CreateGraphics();
System.Drawing.Point po1 = new System.Drawing.Point(500);
System.Drawing.Point po2 = new System.Drawing.Point(1000);
g.DrawLine(p1,po1, po2);


That draws a straight line. Just add some y-coordinates and 3 more lines, and you have a rectangle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top