3

パネルのちらつきを避ける方法が必要です。専門家に尋ねようとして、ここや世界中で多くの同様の質問をしました。多くのトリック、拡張パネル、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
4

4 に答える 4

3

フォームのDoubleBufferedプロパティをTrue

編集 :

タイマーは必要ないと思います。したがって、変更されたコードは次のようになります。

Public Class Form1

    Dim Scroll_Position As Int32 = 0
    Dim SmallChange As Int32 = 5
    Dim Largechange As Int32 = 10

    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
        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 Scroll_Up(ByVal Change As Int32)
        Try
            Scroll_Position -= Change
            Panel1.VerticalScroll.Value = Scroll_Position 
        End Try
    End Sub

    Private Sub Scroll_Down(ByVal Change As Int32)
        Try
            Scroll_Position += Change
            Panel1.VerticalScroll.Value = Scroll_Position 
        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
            scrollDown(smallChange)
        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
            scrollUp(SmallChange)
        End If
    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

これは解決策ではないかもしれませんが、これは私の側の努力です。

于 2013-06-09T06:04:05.633 に答える
3

classとそのコンテンツを表す複合体を使用してから、適切にレンダリングされるpanelペイント ( GDI+) を使用します。Picturebox私はこのようなプロジェクトをいくつか行ってきました。

于 2013-05-31T20:57:14.883 に答える