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 68
|
Public Class Form1
'AJOUTE CE CODE ICI DANS TON FORM ET PAS AILLEURS
'duree de persistance
Dim delaiRectangle As Integer = 500
Dim chrono As Integer
Dim myRectangle As Rectangle = Rectangle.Empty
Dim isDrawing As Boolean = False
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'AJOUTE CE CODE POUR DEMARRER LE TIMER
Me.Timer1.Interval = 10 '10 millisecondes
Me.Timer1.Start()
'chrono demarre
chrono = 0
End Sub
'AJOUTE UN TIMER SUR TON FORM ET CE CODE DANS L'EVENT TICK
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
chrono = chrono + Timer1.Interval
If chrono < delaiRectangle Then
isDrawing = True ' dessin active
Dim w As Integer = 200
Dim h As Integer = 150
myRectangle = New Rectangle(50, 50, w, h)
Me.PictureBox1.Invalidate()
Else
isDrawing = False ' dessin annule
myRectangle = Rectangle.Empty
Me.PictureBox1.Invalidate()
End If
End Sub
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim myGraphics As Graphics = e.Graphics
Dim drawFormat As StringFormat = New StringFormat
drawFormat.Alignment = StringAlignment.Center
drawFormat.Trimming = StringTrimming.Character
'AJOUTE CE CODE DANS L'EVENT PAINT DE TON PICTUREBOX
If isDrawing Then
e.Graphics.FillRectangle(Brushes.Red, myRectangle)
e.Graphics.DrawRectangle(Pens.Black, myRectangle)
myGraphics.DrawString("Nina", Me.PictureBox1.Font, Brushes.Black, myRectangle.X, myRectangle.Y, drawFormat)
Else
'un rectangle vide - neant
e.Graphics.FillRectangle(Brushes.Red, myRectangle)
e.Graphics.DrawRectangle(Pens.Black, myRectangle)
'un string vide - neant
myGraphics.DrawString("", Me.PictureBox1.Font, Brushes.Black, myRectangle.X, myRectangle.Y, drawFormat)
End If
End Sub
End Class |
Partager