【发布时间】:2013-05-27 18:36:14
【问题描述】:
我需要一种方法来避免面板上的闪烁,我在这里和世界各地提出了很多类似的问题,试图向专家提问,我尝试了很多技巧,扩展面板,createparams,controlstyles ,浪费了很多时间,浪费了时间去学习那些行不通的东西......我在这一点上被困了几个月。
...没有什么能真正按预期工作,我发现最好的“Flicker-Reducer”是“Createparams”覆盖子,但该方法使任何表单/应用程序的任何表单操作都慢 20 倍,我如果闪烁也意味着应用程序性能下降(至少如果与 CreateParams 的性能相同的负面影响点则不会)。
在此视频中,您可以看到我的测试表单,其中有一个 50% 透明面板,其中包含背景图像设置为“缩放”分层的图片框,当我向上或向下滚动时,我得到很多闪烁。
http://www.youtube.com/watch?v=zIBDTMjrDd4&feature=youtu.be
我使用“CreateParams”方法,如果我不使用“CreateParams”,真的你不会看到我的面板闪烁会发生什么,真的很可怕。
这是不闪烁时的面板:
这是面板在闪烁的时刻:
这是完整的类:
It is a Windows Form proyect
VS2012
Framework 3.5
On Windows 7 x64
Application Visual Styles is ON
Double Buffer is ON
Panel and pictureboxes are default controls
(我想不用说我已经尝试了人们说我永远忘记闪烁的所有可能的视觉和环境配置。)
Public Class Form1
Dim Scroll_Position As Int32 = 0
Dim Button_Down_Is_Pressed As Boolean = False
Dim Button_Up_Is_Pressed As Boolean = False
Dim WithEvents Progressive_Scroll_Timer As New Timer
Dim SmallChange As Int32 = 5
Dim Largechange As Int32 = 10
' Sub which reduces the Flickering, but this sub makes x20 times slower any operation of any Form/Application.
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H2000000
Return cp
End Get
End Property 'CreateParams
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Me.BackColor = Color.FromArgb(255, 0, 0, 0)
' Me.TransparencyKey = Color.FromArgb(255, 0, 0, 0)
Panel1.VerticalScroll.Maximum = 999999999
Progressive_Scroll_Timer.Interval = 50
Panel1.BackColor = Color.FromArgb(150, 0, 0, 0)
End Sub
Private Sub Panel_MouseHover(sender As Object, e As EventArgs) Handles Panel1.MouseHover
sender.focus()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Progressive_Scroll_Timer.Tick
If Button_Down_Is_Pressed Then
Scroll_Down(SmallChange)
ElseIf Button_Up_Is_Pressed Then
Scroll_Up(SmallChange)
Else
sender.stop()
End If
End Sub
Private Sub Scroll_Up(ByVal Change As Int32)
Scroll_Position -= Change
Panel1.SuspendLayout()
Try : Panel1.VerticalScroll.Value = Scroll_Position : Catch : Scroll_Position += Change : End Try
Panel1.ResumeLayout()
End Sub
Private Sub Scroll_Down(ByVal Change As Int32)
Scroll_Position += Change
Try : Panel1.VerticalScroll.Value = Scroll_Position : Catch : Scroll_Position -= Change : End Try
End Sub
Private Sub Button_Down_MouseDown(sender As Object, e As MouseEventArgs) Handles Button2.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Button_Down_Is_Pressed = True
Progressive_Scroll_Timer.Start()
End If
End Sub
Private Sub Button_Up_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Button_Up_Is_Pressed = True
Progressive_Scroll_Timer.Start()
End If
End Sub
Private Sub Button_Down_MouseUp(sender As Object, e As MouseEventArgs) Handles Button2.MouseUp
Button_Down_Is_Pressed = False
End Sub
Private Sub Button_Up_MouseUp(sender As Object, e As MouseEventArgs) Handles Button1.MouseUp
Button_Up_Is_Pressed = False
End Sub
Private Sub Form_MouseWheel(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseWheel
If Panel1.Focused Then
Select Case Math.Sign(e.Delta)
Case Is > 0 : Scroll_Up(Largechange)
Case Is < 0 : Scroll_Down(Largechange)
End Select
End If
End Sub
End Class
【问题讨论】:
-
请上传您在 YouTube 上展示的一段演示解决方案。
-
您提供的代码缺少重要部分。
-
@Ark-kun 我已经发布了完整的课程,解决方案中没有更多代码(只有图像资源和那个),无论如何这里是完整的解决方案:elektrostudios.tk/WindowsApplication4.rar 谢谢你评论。
-
@Oliver,它是 WS_CLIPCHILDREN 窗口样式常量。 msdn.microsoft.com/en-us/library/windows/desktop/…
标签: .net vb.net visual-studio panel flicker