Problem with PictureBox

B

bassi.carlo

I use a PictureBox to allow users to draw fixed size rectangles.
User click the mouse inside PictureBox and the program read where
mouse is and collect infomations in an array.

Dim Rcs() as Integer 'Rectangles array

Then I call a function who draw rectangles inside PIctureBox1 using
array informations

Private Sub DrawRects()
Dim gr As Graphics = PictureBox1.CreateGraphics
for i = 0 to Rects.GetLength(0)
gr.FillRectangle(Brushes.Red, New System.Drawing.Rectangle(Rcs(i,
0), Rcs(i, 1),Rcs(i, 2),Rcs(i, 0))
next i
End Sub

Everything work well, my problem is if I switch to another application
when I go back my picture box is completely white.
And the same If I resize window.

I tried to put I call to DrawRects function in PictureBox1_Paint event
but don't solve my problem, why?

Thanx in advance
Carlo
 
A

Armin Zingler

I use a PictureBox to allow users to draw fixed size rectangles.
User click the mouse inside PictureBox and the program read where
mouse is and collect infomations in an array.

Dim Rcs() as Integer 'Rectangles array

Then I call a function who draw rectangles inside PIctureBox1 using
array informations

Private Sub DrawRects()
Dim gr As Graphics = PictureBox1.CreateGraphics
for i = 0 to Rects.GetLength(0)
gr.FillRectangle(Brushes.Red, New System.Drawing.Rectangle(Rcs(i,
0), Rcs(i, 1),Rcs(i, 2),Rcs(i, 0))
next i
End Sub

Everything work well, my problem is if I switch to another
application when I go back my picture box is completely white.
And the same If I resize window.

I tried to put I call to DrawRects function in PictureBox1_Paint
event but don't solve my problem, why?


In the paint event, you should use e.graphics instead of calling
Creategraphics to create a new Graphis objects. Not sure if that's the
reason.


Armin
 
B

bassi.carlo

In the paint event, you should use e.graphics instead of calling
Creategraphics to create a new Graphis objects. Not sure if that's the
reason.

Armin- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

This solved my problem, thank you very much Armin
 

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