PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Delaying control repaint. Is it possible?
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Delaying control repaint. Is it possible?
![]() |
Delaying control repaint. Is it possible? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi there,
Using a foreach, I want to iterate (make visible) all the tabpages of a tabcontrol, in order to activate the databinding of the controls in each tabpage. Is there a way to delay/disable the repainting until the iteration is done, so the user doesn't see the tabpages switching? Something like: -Disable control repaint in the form -Iterate the tabpages -Enable control repaint (and then the last tabpage activated is shown instantly) Regards, -Benton Using VS 2005 Beta 2 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
> Is there a way to delay/disable the repainting until the iteration is done,
> so the user doesn't see the tabpages switching? Something like: > > -Disable control repaint in the form > -Iterate the tabpages > -Enable control repaint (and then the last tabpage activated is shown > instantly) I struggled with a similar problem and came to the solution described below. My setting is a rich text box (rtb) with many updates for highlighting, and I wanted to avoid flicker associated with each update. The idea is to handle the Invalidated event for the rtb. You may need to handle it for just the tab control or, or maybe for each page, or maybe each control - I dont know. In the Invalidated event, I call the win32 api ValidateRect to make windows think it does not need to paint the control. You need something like this: Friend Declare Function ValidateRect Lib "user32" ( _ ByVal hWnd As Integer, _ ByVal lpRect As Integer) _ As Integer and this: ValidateRect(MyControl.Handle.ToInt32, 0) where MyControl is a control (rtb in my case, something else in yours). To put all this together, I have two boolean variables associated with the rtb, a frozen flag and a dirty flag. When I want to inhibit painting, I set frozen to true and dirty to false. In the Invalidated event, I do nothing if not frozen, otherwise I call ValidateRect and set the dirty flag to true. To resume painting, I set frozen to false, and if dirty, I Invalidate the rtb. There may be a better way, but all other stabs I tried either failed or had some side effect (eg a different kind of flicker). |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

