Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the issue i am facing

I have a form with a Panel added let's call it PanelFloorPlan

When i refresh all my Tables (Buttons) into the PanelFloorPlan (Using Timer), the Button Flicker. It gets worst when my PanelFloorPlan has a Background Image. I have tried "Me.PanelFloorPlan.SuspendLayout()" and "Me.PanelFloorPlan.ResumeLayout()". But it's not working.

I have tried "Me.DoubleBuffered = True" but it's still the same.

Please Help! Thanks.

VB
Private Sub frmForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Timer.Interval = 3000
        Timer.Enabled = True
        Me.DoubleBuffered = True
        GetTableList()  
        PanelFloorPlan.BackgroundImage = Image.FromFile("c:\FloorPlan.jpg")  
End Sub  
  
Private Sub GetTableList()  
        Me.PanelFloorPlan.SuspendLayout()  
        Me.PanelFloorPlan.Controls.Clear()  
        Dim strSelectCmd As String = "SQL Command"  
        Try  
            sqlCmd = New SqlClient.SqlCommand(strSelectCmd, sqlConn)  
            If Not sqlConn.State = ConnectionState.Open Then  
                sqlConn.Open()  
            End If  
            sqlRdr = sqlCmd.ExecuteReader()  
            While sqlRdr.Read()  
                'Define Btn and Set Parameters to the Button  
                Dim Btn As New Button  
                Btn.Name = sqlRdr("TableName").ToString  
                'Add Buttons to Form  
                Me.PanelFloorPlan.Controls.Add(Btn)  
            End While  
            Me.PanelFloorPlan.ResumeLayout()  
            sqlRdr.Close()  
            sqlConn.Close()  
        Catch ex As Exception  
            MessageBox.Show("GetTableList Error : " & ex.Message)  
            sqlConn.Close()  
        End Try  
 End Sub  
  
Private Sub Timer_Tick(sender As System.Object, e As System.EventArgs) Handles Timer.Tick  
        GetTableList()  
End Sub  
Posted
Comments
Thava Rajan 7-Nov-14 2:48am    
try to use the setstyles in form
William Chan Choon Huat 8-Nov-14 3:38am    
JNDIONYSIM suggest a setstyles example and it works. Thank you.

I had this problem too and i solved it by creating a class that inherits from Panel and added the following code

VB
Public Class myPanel
    Inherits Panel

    Public Sub New()
        MyBase.New()
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    End Sub

    Protected Overrides Sub OnScroll(se As ScrollEventArgs)
        Me.Invalidate()

        MyBase.OnScroll(se)
    End Sub
    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or &H2000000
            ' WS_CLIPCHILDREN
            Return cp
        End Get
    End Property

Do this rebuild your project and use myPanel control insteed of panel control.
That worked for me.

I found this code somewhere in a forum but idont remember where (i hope this is not a problem)
 
Share this answer
 
v2
Yes, this works for me. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900