473,480 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with PictureBox

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

Sep 12 '07 #1
2 1519
<ba*********@gmail.comschrieb
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

Sep 12 '07 #2
On 12 Set, 17:10, "Armin Zingler" <az.nos...@freenet.dewrote:
<bassi.ca...@gmail.comschrieb


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- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
This solved my problem, thank you very much Armin

Sep 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1790
by: chau_fai | last post by:
I have a window Form called "Form2". There is only one button and a panel returned from a static method of the "Coord" in this form. In the panel returned, there is a button that can choose image...
1
4158
by: James Dean | last post by:
I am drawing in a picturebox and am having some problems. I display outputted images in the picturebox. If the image is too big for the client area then i have scrollbars. The problem is that once...
7
3208
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image...
1
5421
by: Martin Horn | last post by:
Hi all, I'm trying to save a picturebox image to a database. This is part of the code I'm using:- <snip> Private drv As DataRowView Private dr As MainDataSet.OrdersRow If...
0
1541
by: Ben3eeE | last post by:
I got one too hard for me to fix problem. I know the cause and i know why but i cant fix it. I am using a "Rubber band" like function, drawing a rectangle on an image in a picturebox that i...
7
3426
by: MasterMax1313 | last post by:
I'm trying to make a grid of picture box controls, which I do via code. Each of these boxes has a mouseclick, mousedown, mouseup, and mouseenter event. The mouseclick event is simple enough and works...
7
2977
by: active | last post by:
In control panel/Display/Appearance/Effects if : 'Use the following method to smooth edges of screen fonts' is checked and ClearType is selected in the combobox (no problem if Standard is...
27
13952
by: Phil | last post by:
I thought it would be nice to display some animated GIFs on some of my forms. I put a PictureBox control on a form, and loaded my GIF file in. It animates, but not properly. It seems very jerky and...
0
1707
by: Truevision .Net | last post by:
Hi, I have a problem with drag and drop functionality when it comes to dropping pictures from sources like for example internet explorer and the webbrowser control. Dragging and dropping from...
6
10189
by: babaidebnath | last post by:
Hello all, I am presently having a problem with printing in C#. The problem is my customer provided me a pre printed paper and I need to print value into some specific positions. But problem is C#...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.