나는 친절하기 때문에 새로운 이벤트. 기본적으로 그림 상자에 .gif를 페인트하여 flowlayout 패널에 추가하려고합니다. 그 이유는 프레임 수를 세지 않고 페인트하지 않으면 gif가 계속 반복되는 것입니다.Hookup 새로운 Picturebox 페인트 이벤트
기본적으로 하나의 클래스 내에서 picturebox를 만들었고, 페인트 이벤트를 연결하고 클래스가 기본 폼 클래스에서 새롭게 될 때 페인트 이벤트를 발생 시키려고합니다. 어쩌면 내가 잘못하고있는 것일 수도 있습니다. 아마도 이것이 최선의 방법이 아니거나 어쩌면 누군가가 더 나은 방법을 제안 할 수 있습니다. 현재 클래스 폼을 기본 폼이라고 부르면 클래스 변수가 단계별로 실행되지만 "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
가 그럼 난 기본 폼에서 테스트 버튼이 클래스를 새로운 아래에 내 코드를 참조하십시오. 어쩌면 내가 뭔가를 놓친 것 같아.