1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
Public Class Form1
Private bBuffer As Bitmap = Nothing
Private r As Rectangle = Rectangle.Empty
Private dtStarted As Date = Now
Private intStep As Integer = 1
Private intTickCount As Integer = 0
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "toto"
End Sub
Private ReadOnly Property Buffer() As Bitmap
Get
If bBuffer Is Nothing Then
ResetBuffer()
End If
Return bBuffer
End Get
End Property
Private Sub ResetBuffer()
If r = Rectangle.Empty Then
r = New Rectangle(0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height)
End If
bBuffer = New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
Dim gd As Graphics = Graphics.FromImage(bBuffer)
Dim MaFont As Font
Dim MaBrush As Brush
MaFont = New Font("DS-Digital", 15, FontStyle.Italic)
MaBrush = New SolidBrush(Color.LimeGreen)
gd.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)
gd.DrawString(intTickCount.ToString, MaFont, MaBrush, New Point(0, 0))
gd.DrawString(dtStarted.ToString, MaFont, MaBrush, New Point(0, 50))
gd.DrawString(Now.ToString, MaFont, MaBrush, New Point(0, 100))
gd.DrawRectangle(Pens.Red, r)
gd.Dispose()
Me.Refresh()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(Me.Buffer, 0, 0)
End Sub
Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaintBackground(pevent)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
r.Width -= intStep
r.Height -= intStep
intTickCount += 1
ResetBuffer()
If r.Width = 1 Or r.Height = 1 _
Or r.Width = Me.Bounds.Width Or r.Height = Me.Bounds.Width Then
intStep = -intStep
End If
End Sub
End Class |
Partager