问题描述
这是我面临的问题
我有一个面板添加了一个面板让我们称之为PanelFloorPlan
当我将所有表格(按钮)刷新到PanelFloorPlan(使用计时器)时,按钮闪烁。当我的PanelFloorPlan具有背景图像时,它变得最糟糕。我尝试过Me.PanelFloorPlan.SuspendLayout()和Me.PanelFloorPlan.ResumeLayout()。但它不起作用。
我试过Me.DoubleBuffered = True但它仍然是一样的。
请帮助!谢谢。
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.
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
推荐答案
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
这样做会重建你的项目并使用myPanel控制来控制面板控制。
这对我有用。
我在论坛的某个地方找到了这个代码但是忘记了哪里(我希望这不是问题)
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)
这篇关于当我添加到具有Backgroudimage的面板时按钮闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!