• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Flicker free picturebox

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
OTveit
Asked:
OTveit
  • 2
  • 2
1 Solution
 
skerrypaCommented:
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
 
Erick37Commented:
"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
 
OTveitAuthor Commented:
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
 
Erick37Commented:
Can you post the code here so we can take a look?
0
 
OTveitAuthor Commented:
 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now