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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| Public Class Form1
Private BufferredGraphic As BufferedGraphics
Private CurrentContext As BufferedGraphicsContext
Private WithEvents board As New PictureBox
Private flagshow As Boolean
Private WithEvents buttonshow As New Button
Public Class losangedata
Private points(4) As System.Drawing.Point
Private colorlosange As Brush
Public Property pointlosange() As Point()
Get
Return points
End Get
Set(ByVal value As Point())
points = value
End Set
End Property
Public Property lacolorlosange() As Brush
Get
Return colorlosange
End Get
Set(ByVal value As Brush)
colorlosange = value
End Set
End Property
End Class
Private listlosange As New List(Of losangedata)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
buttonshow.Location = New Point(10, 0)
buttonshow.Text = "affiche"
board.Width = ClientRectangle.Size.Width
board.Height = ClientRectangle.Size.Height - buttonshow.Height
board.Location = New Point(0, buttonshow.Height)
board.BackColor = Color.LightGoldenrodYellow
CurrentContext = BufferedGraphicsManager.Current
BufferredGraphic = Me.CurrentContext.Allocate(board.CreateGraphics(), board.DisplayRectangle)
BufferredGraphic.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Me.Controls.Add(board)
Me.Controls.Add(buttonshow)
InitLosange()
Windows.Forms.Cursor.Position = New Point(0, 0)
flagshow = False
End Sub
Private Sub InitLosange()
Dim leftpos, toppos, side As Integer
side = 24
leftpos = side \ 2
toppos = 2
For item As Integer = 0 To 799
Dim thelosange As New losangedata
thelosange.pointlosange(0).X = leftpos
thelosange.pointlosange(0).Y = toppos
thelosange.pointlosange(1).X = thelosange.pointlosange(0).X + side \ 2
thelosange.pointlosange(1).Y = thelosange.pointlosange(0).Y + side \ 2
thelosange.pointlosange(2).X = thelosange.pointlosange(0).X
thelosange.pointlosange(2).Y = thelosange.pointlosange(1).Y + side \ 2
thelosange.pointlosange(3).X = thelosange.pointlosange(0).X - side \ 2
thelosange.pointlosange(3).Y = thelosange.pointlosange(1).Y
thelosange.pointlosange(4) = thelosange.pointlosange(0)
thelosange.lacolorlosange = Brushes.RoyalBlue
listlosange.Add(thelosange)
leftpos += side
If item Mod 40 = 39 And item <> 0 Then
leftpos = side \ 2
toppos += side
End If
Next
End Sub
Private Sub DrawLosange()
BufferredGraphic.Graphics.Clear(Color.LightGoldenrodYellow)
For Each item As losangedata In listlosange
BufferredGraphic.Graphics.FillPolygon(item.lacolorlosange, item.pointlosange)
Next
board_Paint(board, New PaintEventArgs(Me.BufferredGraphic.Graphics, board.DisplayRectangle))
End Sub
Private Sub board_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles board.MouseMove
For Each item As losangedata In listlosange
If e.X > item.pointlosange(3).X And e.X < item.pointlosange(1).X And e.Y > item.pointlosange(0).Y And e.Y < item.pointlosange(2).Y Then
BufferredGraphic.Graphics.FillPolygon(Brushes.Red, item.pointlosange)
End If
Next
board_Paint(board, New PaintEventArgs(Me.BufferredGraphic.Graphics, board.DisplayRectangle))
End Sub
Private Sub board_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles board.Paint
If flagshow Then
BufferredGraphic.Render()
End If |
Partager