Solved

Flicker free picturebox

Posted on 2000-04-10
5
382 Views
Last Modified: 2008-03-17
I have a PictureBox wich I draw different objects in, using the Line, PSet and Circle method. I move these objects around by clearing the entire PictureBox and redrawing them in a different position. The PictureBox also contains a background (Gridlines) which are not moved.  The problem is that this method makes the objects flicker. Is there a smarter way to do this?
0
Comment
Question by:OTveit
[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
  • 2
  • 2
5 Comments
 

Expert Comment

by:skerrypa
ID: 2700452
If you use the Windows API call LockWindowUpdate, you can pass the hWnd of the Picture Box and Windows will not update that area of the screen.  

Once you've finished drawing your objects on the picture box, call LockWindowUpdate, but with a 0 (zero) in place of the control handle, and the picture box will be redrawn with all your changes.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2700487
"Its a common problem that controls seem to flicker as they are updated. This can be due to Windows updating a control's screen image multiple times during an update or Windows updating a control during the monitor vertical refresh. The technique below gives you the ability to lock individual controls or the entire form window during updates, this allows you to dictate to Windows when the screen updating should be done."

Private Declare Function LockWindowUpdate Lib "User32" _
    (ByVal hWnd As Long) As Long

'...

' Lock the control to prevent redrawing
LockWindowUpdate Picture1.hWnd
'Draw everything here
'Then unlock the window
LockWindowUpdate 0
0
 

Author Comment

by:OTveit
ID: 2704477
The LockWindowUpdate works ok for my PictureBox - it does not flicker. But erverything else does, both in my application and the entire Windows environment.......????
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2704716
Can you post the code here so we can take a look?
0
 

Author Comment

by:OTveit
ID: 2705268
 Ooops... ! During cutting and pasting to post the code here I noticed that I had a PictureBox1.Cls command outside the LockWindowUpdate. Moving it between the LockWindowUpdate PictureBox1.hWnd and LockWindowUpdate 0 made the flickering dissapear....

Thanks!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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