I am calling the following code from my main program. I checked with the debugger and the code gets executed. However, there is no rectangle drawn on the screen. Any idea why?
thanks
Graphics surface = this.CreateGraphics();
Pen pen1 = new Pen(System.Drawing.Color.Red, 1.0f);
Rectangle rec1 = new Rectangle(10, 10, 100, 100);
PaintEventArgs arg = new PaintEventArgs(surface, rec1);
DrawRectangleRectangle(arg);
private void DrawRectangleRectangle(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);
// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, rect);
}
acheo
Member
81 Points
67 Posts
problems with drawing a rectangle .NET 4.0
Jun 19, 2012 08:04 PM|LINK
I am calling the following code from my main program. I checked with the debugger and the code gets executed. However, there is no rectangle drawn on the screen. Any idea why?
thanks
Graphics surface = this.CreateGraphics(); Pen pen1 = new Pen(System.Drawing.Color.Red, 1.0f); Rectangle rec1 = new Rectangle(10, 10, 100, 100); PaintEventArgs arg = new PaintEventArgs(surface, rec1); DrawRectangleRectangle(arg); private void DrawRectangleRectangle(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); // Create rectangle. Rectangle rect = new Rectangle(0, 0, 200, 200); // Draw rectangle to screen. e.Graphics.DrawRectangle(blackPen, rect); }