Solved

Flicker free picturebox

Posted on 2000-04-10
5
380 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

791 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