2016-08-06 4 views
0

私はイベントに慣れていないので、優しいです。基本的に私は.gifをピクチャボックスにペイントして、フローレイアウトパネルに追加しようとしています。これは、フレームを数えずに塗りつぶしてもgifがループしているということです。フックアップ新しいPictureboxペイントイベント

基本的に私は1つのクラス内にピクチャボックスを作成しました。クラスをメインフォームクラスで新規に作成すると、ペイントイベントが発生し、ペイントイベントが発生します。たぶん私は間違っている、多分これはベストプラクティスではないかもしれないか、誰かがそれをやるより良い方法を提案するかもしれない。現在私がクラスフォームをメインフォームと呼ぶとき、クラス変数はステップスルーされますが、私は "withevents"が踏み出されると宣言したピクチャボックスを見ることはありません。また、Paintイベントは決してステップに入ることはありません。

Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click 
    Dim chkMark As CompleteMark 
    chkMark = New CompleteMark(flpAdobeLbl) 
End Sub 

のPictureBoxをフォーム上に作成され、.GIFは現れないが、何のアニメーション:その後、私は、メインフォーム上のテストボタンでこのクラスを新しい

Public Class CompleteMark 
    Implements IDisposable 

    Dim WithEvents _picBox As PictureBox 

#Region "VARIABLES" 

    'Disposable variables 
    Private managedResource As System.ComponentModel.Component 
    Private unmanagedResource As IntPtr 
    Protected disposed As Boolean = False 

    'Class Variables 
    Dim _cm As New Bitmap(My.Resources.cmt) 
    Dim _currentlyAnimating As Boolean = False 
    Dim _frameCounter As Integer = 0 
    Dim _frameCount As Integer 
    Dim _frameDim As Imaging.FrameDimension 


    '_picBox = New PictureBox() 




#End Region 

    Sub New(ByVal flp As FlowLayoutPanel) 
     _picBox = New PictureBox() 
     _picBox.Size = New Size(14, 13) 
     _picBox.Margin = New Padding(0, 0, 0, 0) 
     _picBox.Name = "AnimCheckMark" 
     _picBox.Image = _cm 
     flp.Controls.Add(_picBox) 
     _picBox.Invalidate() 

     'AddHandler _picBox.Paint, AddressOf AnimCheckMark_Paint 

    End Sub 

    Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs) 
     _picBox.Invalidate() 
    End Sub 

    Private Sub AnimateImage() 
     If Not _currentlyAnimating Then 
      ImageAnimator.Animate(_cm, New EventHandler(AddressOf OnFrameChanged)) 
      _currentlyAnimating = True 
     End If 
    End Sub 

    Private Sub AnimCheckMark_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles _picBox.Paint 
     _frameDim = New Imaging.FrameDimension(_cm.FrameDimensionsList(0)) 
     _frameCount = _cm.GetFrameCount(_frameDim) 

     If _frameCounter < _frameCount Then 
      AnimateImage() 
      ImageAnimator.UpdateFrames() 
      e.Graphics.DrawImage(_cm, New Point(0, 0)) 
      _frameCounter += 1 
     End If 
    End Sub 

#Region " IDisposable Support " 

    Protected Overridable Overloads Sub Dispose(
      ByVal disposing As Boolean) 
     If Not Me.disposed Then 
      If disposing Then 
       managedResource.Dispose() 
      End If 
      ' Add code here to release the unmanaged resource. 
      unmanagedResource = IntPtr.Zero 
      ' Note that this is not thread safe. 
     End If 
     Me.disposed = True 
    End Sub 

    Public Sub AnyOtherMethods() 
     If Me.disposed Then 
      Throw New ObjectDisposedException(Me.GetType().ToString, 
        "This object has been disposed.") 
     End If 
    End Sub 


    ' Do not change or add Overridable to these methods. 
    ' Put cleanup code in Dispose(ByVal disposing As Boolean). 
    Public Overloads Sub Dispose() Implements IDisposable.Dispose 
     Dispose(True) 
     GC.SuppressFinalize(Me) 
    End Sub 
    Protected Overrides Sub Finalize() 
     Dispose(False) 
     MyBase.Finalize() 
    End Sub 
#End Region 

End Class 

の下に私のコードを参照してください。たぶん私は何かが欠けているでしょう。

答えて

0

おっと!それを解決しました。上のコードはイベントに接続するためにうまく動作します。私はちょうど愚かにイベントハンドラにブレークポイントを設定していないので、VSはそれにステップインしていませんでした。

明らかに、VSはブレークポイントがあればイベントハンドラに入るだけです。

関連する問題