新学GDI+,写的一个很好玩的代码
Public NotInheritable Class AniForm
Private Delegate Sub AniControlSub(ByVal ControlSource As Control)
Private _Source As Form
Public Sub New(ByVal SourceForm As Form)
_Source = SourceForm
End Sub
Public Sub StartAni()
Dim mC As Control
Dim mS(_Source.Controls.Count - 1) As AniControlSub
Dim i As Integer
For Each mC In _Source.Controls
mC.Visible = False
Next
For Each mC In _Source.Controls
mS(i) = New AniControlSub(AddressOf DrawControl)
mS(i).BeginInvoke(mC, Nothing, Nothing)
i = i + 1
Next
End Sub
Private Sub DrawControl(ByVal ControlSource As Control)
Dim C As Integer = 5 '循环次数
Dim G As Graphics = _Source.CreateGraphics()
Dim pen As Pen = New Pen(Color.Black, 1)
Dim epen As Pen = New Pen(_Source.BackColor, 1)
Dim rect As Rectangle = New Rectangle(ControlSource.Left + ControlSource.Width \ 2, ControlSource.Top + ControlSource.Height \ 2, 1, 1)
Dim i As Integer
Dim cx As Integer = ControlSource.Width \ C \ 2
Dim cy As Integer = ControlSource.Height \ C \ 2
'ControlSource.Visible = False
For i = 0 To C - 1
G.DrawRectangle(epen, rect)
rect.Inflate(cx, cy)
G.DrawRectangle(pen, rect)
Threading.Thread.Sleep(30)
Next
G.DrawRectangle(epen, rect)
ControlSource.Visible = True
'ControlSource.Refresh()
End Sub
End Class
用法:
dim a as myform=new myform
dim p as AniForm=new AniForm(a)
a.show
p.StartAni
你会看到控件像泡泡一样冒出来
如果你的窗体上面空间很多的话,效果很好的 :-)
如果你喜欢这段代码,请给一个回复。我会继续写更好玩的代码 :-)