我需要一種方法來避免閃爍在面板上,我在這裏做了很多類似的問題和世界上所有的試圖詢問專家身邊,我已經嘗試了很多花樣,擴展板,的CreateParams,的ControlStyles,失去了很多的時間,浪費時間學習的東西會不工作......我被困在這一點上幾個月。面板閃爍與Pictureboxes
...沒有什麼能像預期的那樣真正起作用,我發現的最好的「Flicker-Reducer」是「Createparams」重寫子,但是這種方法使Form/App x20的任何操作都變得更慢,我不想失去閃爍如果這意味着寬鬆的應用性能太(至少不是如果是的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我已經發布了完整的類,解決方案中沒有更多的代碼(只有圖像資源和那個),反正這裏是完整的解決方案:http://elektrostudios.tk/WindowsApplication4.rar感謝你的評論。 – ElektroStudios