Hi all,
Visual Studio 2017, Visual Basic, .Net Framework 4.6.1
I have a windows form application with one form with 4 panels stacked on top of one another containing various controls. as the user selects a panel (by clicking a button in ribbon) the desired panel is brought to the front. This works well except there is a flicker as the panel is brought to front. It very briefly shows both parts of the panel it is transitioning from and parts of the panel it is transitioning to.
I have tried various methods to reduce the flicker but the one that seems to work best is setting the exstyle of the form to WS_EX_COMPOSITED. It works perfectly, the transitions are crisp without any flicker until a resize is performed and then the flicker returns. It seems a resize invalidates or overrides the WS_EX_COMPOSITED flag even though it still shows as being set. resetting the flag does not restore the crisp functionality. There are no resize events firing only what is done natively.
Thanks for any help or ideas you may have
Visual Studio 2017, Visual Basic, .Net Framework 4.6.1
I have a windows form application with one form with 4 panels stacked on top of one another containing various controls. as the user selects a panel (by clicking a button in ribbon) the desired panel is brought to the front. This works well except there is a flicker as the panel is brought to front. It very briefly shows both parts of the panel it is transitioning from and parts of the panel it is transitioning to.
I have tried various methods to reduce the flicker but the one that seems to work best is setting the exstyle of the form to WS_EX_COMPOSITED. It works perfectly, the transitions are crisp without any flicker until a resize is performed and then the flicker returns. It seems a resize invalidates or overrides the WS_EX_COMPOSITED flag even though it still shows as being set. resetting the flag does not restore the crisp functionality. There are no resize events firing only what is done natively.
Thanks for any help or ideas you may have
Code:
'Set on all controls and Form in different combinations, These did not work
'MyBase.DoubleBuffered = True
'MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
'MyBase.SetStyle(ControlStyles.UserPaint, True)
'MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
'Override ExStyle, Works until form is resized
Public OriginalExStyle As Integer = -1
Public EnableFormLevelDoubleBuffering As Boolean = True
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
If OriginalExStyle = -1 Then
OriginalExStyle = MyBase.CreateParams.ExStyle
End If
Dim Params As CreateParams = MyBase.CreateParams
If EnableFormLevelDoubleBuffering Then
Params.ExStyle = 33554432 'WS_EX_COMPOSITED
Else
Params.ExStyle = OriginalExStyle
End If
Return Params
End Get
End Property
'Change ExStyle
Public Sub FormLevelDoubleBuffering(State As Boolean)
EnableFormLevelDoubleBuffering = State
MyBase.MaximizeBox = True ' Force reload of styles
End Sub
' Switch between panels
Private Sub setView(myView As Panel)
myView.BringToFront()
End Sub