Solved

Flicker free picturebox

Posted on 2000-04-10
5
370 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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
Comment Utility
Can you post the code here so we can take a look?
0
 

Author Comment

by:OTveit
Comment Utility
 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
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…

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now