Solved

Flicker free picturebox

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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