?
Solved

Refreshing graphics on a picture box

Posted on 2004-08-17
7
Medium Priority
?
270 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
ptakja earned 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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