Rectangle not visible

P

Peter

I have the following code, which draws a ractangle on a picture box, but the
rectangle does not become visible until I overlay another Window over the
picture box and remove this window. How can I fix this problem?


private static void PictureBox1_paint( object sender, PaintEventArgs e )
{
// Get Graphics Object
Graphics g = e.Graphics;

// Create pen
Pen bluePen = new Pen( Color.Blue, 2 );

// Draw rectangle to screen
g.DrawRectangle( bluePen, 10, 10, 220, 150 );

bluePen.Dispose();
}


Thank You


Peter
 
P

Peter Huang [MSFT]

Hi Peter,

Thanks for your information, it is strange that I can not reproduce the
problem.
I test on both .NET 1.1 and .NET 2.0.
Here is my test steps, you may have a try.
1. Create a new winform application
2. Add a picturebox control
3. set the Dock property to Fill
4. Handle the Paint event and copy/paste the code as you post
// Get Graphics Object
Graphics g = e.Graphics;
// Create pen
Pen bluePen = new Pen(Color.Blue, 2);
// Draw rectangle to screen
g.DrawRectangle(bluePen, 10, 10, 220, 150);
bluePen.Dispose();

Press Ctrl+F5 to run the code, I will the blue rectange on the picture.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top