0

I've developed a program that inserts an array of Panel-like controls into another Panel control, the code is as follows:

Dim ModSe As Bitmap = Nothing
ModSe = My.Resources.example

Dim pbdoors As New Panel With {
    .Width = 100,
    .Height = 200,
    .Top = 10,
    .Left = 10,
    .BorderStyle = BorderStyle.FixedSingle,
    .BackgroundImage = ModSe,
    .BackgroundImageLayout = ImageLayout.Stretch,
    .ContextMenuStrip = CntxtMnuStrpUnit,
    .Name = ("Test")
}

But when I see the arrangement of Panel controls already inserted, when I step over a control type Tab, they start to flash as if it were a strobe light. In this case, for my Form, I went to the "DoubleBuffered" property and set it to True, but it keeps flashing.

Add the following without any results.

Public Class FlickerPanel
    Inherits System.Windows.Forms.Panel

    Public Sub New()
        MyBase.New()

        Me.SetStyle(ControlStyles.Opaque, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(ControlStyles.EnableNotifyMessage, True)
    End Sub

    Protected Overrides Sub OnNotifyMessage(ByVal m As Message)
        If (m.Msg <> &H14) Then
            MyBase.OnNotifyMessage(m)
        End If
    End Sub
End Class

Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        'Dim cp As CreateParams = MyBase.CreateParams
        'cp.ExStyle = cp.ExStyle Or 33554432

        'Return cp

        Dim cp As CreateParams = MyBase.CreateParams
        Dim OSVer As Version = System.Environment.OSVersion.Version()
        Select Case OSVer.Major
            Case Is <= 5
            Case 5
                If OSVer.Minor > 0 Then
                    cp.ExStyle = cp.ExStyle Or &H2000000
                End If
            Case Is > 5
                cp.ExStyle = cp.ExStyle Or &H2000000
            Case Else
        End Select
        Return cp
    End Get
End Property

Please, how can I eliminate this flicker?

Jimi
  • 29,621
  • 8
  • 43
  • 61
LARC
  • 79
  • 1
  • 10
  • You cannot have this: `Me.SetStyle(ControlStyles.Opaque, True` and this: `Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True` together when coupled with `cp.ExStyle = cp.ExStyle Or &H2000000` (`WS_EX_TRANSPARENT`). Trying to double-buffer a transparent Control without background will only cause misery. – Jimi Sep 29 '21 at 21:34
  • See: [Transparent image over two controls with different back colors](https://stackoverflow.com/a/54261539/7444103) and [Translucent circular Control with text](https://stackoverflow.com/a/51435842/7444103). Also, there's a specific reason to make transparent a Control derived from Panel, because of its *special behavior* (e.g., [Transparent Overlapping Circular Progress Bars (Custom Control)](https://stackoverflow.com/a/53379442/7444103)), but you probably don't want that. Derive from `Control` directly (remembering that double-buffering and transparency don't work together *out of the box*). – Jimi Sep 29 '21 at 21:42
  • BTW, `CreateParams` is usually overridden *inside* its class :) – Jimi Sep 29 '21 at 21:46

0 Answers0