473,606 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ 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.Cre ateGraphics
for i = 0 to Rects.GetLength (0)
gr.FillRectangl e(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_Pai nt event
but don't solve my problem, why?

Thanx in advance
Carlo

Sep 12 '07 #1
2 1530
<ba*********@gm ail.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.Cre ateGraphics
for i = 0 to Rects.GetLength (0)
gr.FillRectangl e(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_Pai nt
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...@free net.dewrote:
<bassi.ca...@gm ail.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.Cre ateGraphics
for i = 0 to Rects.GetLength (0)
gr.FillRectangl e(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_Pai nt
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
1801
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 from "OpenFileDialog" and then display it in a picturebox. This actually works properly before the button1 is clicked. Button1 is a button to open a new form and again it gets a panel returned from the static method inside "Coord" and perform the...
1
4170
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 i draw a bitmap to the picturebox I have trouble displaying graphics inside the picturebox. I pictureBox1.image = Image.FromFile("OutBinary.bmp"); This image is displayed in the picturebox with scrollbars. Then i try to
7
3219
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 is drawn by loading a jpg into a bitmap and then setting picturebox.image = mybitmap. Ive created my own class, inheriting from the picturebox and overriding the OnPaint event so I can do e.Graphics.DrawImage (this.image....). This renders...
1
5432
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 PictureBox.Image IsNot Nothing Then
0
1548
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 loaded. Now i want to Cut out the part i marked with the "Rubber band" and load that image in the picturebox. This works great and i can save that image as i want to. The problem is that the image loaded is smaller cause when i load the image i use...
7
3441
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 fine. However, i use the mousedown, mouseup, and mouseenter events to be able to click and drag to apply the same image across all of the boxes the mouse enters (similar to a terrain editor for a game like StarCraft). I set a form wide boolean...
7
2989
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 selected) I get a crazy font display in parts of my picturebox.
27
13993
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 dwells on some frames longer than it should. Searching for this problem, I have found several people who have stated that animated GIFs don't work in a PictureBox at all, and you have to use the ImageAnimator. I assume they must be referring to...
0
1714
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 picturebox to picturebox works just fine. This part of the program is basically that it navigates to a page in a webbrowser control and on this page there are several pictures to chose from. I want to drag and drop one of them to a picturebox and
6
10228
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# for its generic autofit to page nature dont let me doing this. Every time it is decreasing whole page's size and also altering my value position into some specific ratio. Can anyone tell me how can I come over that problem. This is my code
0
8015
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7951
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8094
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5465
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3930
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.