Solved

Refreshing graphics on a picture box

Posted on 2004-08-17
7
268 Views
Last Modified: 2008-02-26
Hello

I have a picture box where i display graphics using gdi functions.

Dim g As Graphics
g = Pic_Dessin.CreateGraphics
...
and so on....

The graphics are redrawn anytime i change a value in the textboxes on the same form.
I want the picture to displayed at all time.

I tried to solutions :

1- Draw on loading and on form activation (MyBase.Activated, MyBase.GotFocus events)
Problem : Image tends to disapear for no reason after loading, and occasionally, when i click on a textbox (this seems pretty random for me)

2- Use a timer to refresh the drawing every 800 ms
Problem : each time the graphics are redrawn, the picture box goes white for a moment, which doesn't look too good...

I'm out of ideas now, and i will appreciate help ^^
Thx in advance

0
Comment
Question by:SweetNenya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 11821903
You need to draw your items in the Picbox's PAINT event.  The Paint event will pass an "e" argument which will give you access to the graphics object in the picturebox as:

e.Graphics

Use this to do your drawing.  When you want to update the image, simple execute PictureBox1.Invalidate() which will force the repaint.

Jeff
0
 

Author Comment

by:SweetNenya
ID: 11822104
First, let me be sure i got this right :

Private Sub Dessin(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Pic_Dessin.Paint
         'Drawing function here
End Sub

Now, at loading, the graphics are drawned, erased, and redrawn (all this is quite fast, so it doesn't matter too much)
Even though, for some (unknown) reason, when i pressed TAB to go from one textbox to another, the drawing disappear... any idea why?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11822141
Or let your redrawing be handled by the mybase.activated event, and the textbox textchanged

Private Sub RedrawPicture(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated, txtColor1.TextChanged ' etc...



end sub
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 14

Accepted Solution

by:
ptakja earned 200 total points
ID: 11822207
Come to think of it, if you are drawing your own images using GDI+, the picturebox is overkill.  You can draw on any surface using GDI+.  Have you tried drawing to a Panel control?  The Picbox has a ton of overhead designed to make image manipulation a breeze.  You aren't utilizing any of that (at least as far as I can tell from your post).

Try replacing your Picbox with a Panel and handle the Panel's paint event and do your drawing in there.
0
 

Author Comment

by:SweetNenya
ID: 11822243
Hmm, this is what i described in my "solution 1" in my first post...

Actually, i think the problem could be easy to solve if i knew why the image is erased... but i have no idea =/
0
 

Author Comment

by:SweetNenya
ID: 11822575
I replaced the picture box by a panel, and the graphics works fine now ^^
I would never tried that by myself, thx a lot ptakja
0
 
LVL 14

Expert Comment

by:ptakja
ID: 11822614
Your welcome.  Glad I could help!  

Jeff
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question