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
|
Public Class Form4
'-------------------rectangle grid----------
Private rectGrille As Rectangle
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'-------------------coords winform(origine top, left) ----------
Me.Text = "Coords Panel :" & Me.Panel1.Location.X.ToString & " , " & Me.Panel1.Location.Y.ToString
Me.Font = New Font("tahoma", 12)
'-------------------coords panel (origine centre panel ) ----------
rectGrille = New Rectangle(0, 0, 0, 0)
Me.Panel1.Dock = DockStyle.Fill
'-----------------------mets à jour l'affiche sur resizin du form-----------------------
Me.ResizeRedraw = True
End Sub
'dessine un grid sur le panel
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
e.Graphics.Clear(Color.White)
'rectangle client panel
Dim tempRect As Rectangle = Me.Panel1.ClientRectangle
'inflate veut dire"reduire" les 2 dimensions de -20,-20 ou "dilater" de 20,20
tempRect.Inflate(-20, -20)
rectGrille = tempRect
'dessine bord rectangulaire de la grille(coords par rapport au form 20,20)
e.Graphics.DrawRectangle(Pens.Black, rectGrille)
' dessine grille de points espace de 15,15 pixels
ControlPaint.DrawGrid(e.Graphics, rectGrille, New Size(15, 15), Color.White)
'dessine une croix au centre du rectangule de la grille
Dim penCroix As Pen = New Pen(Color.Brown, 1.0)
penCroix.EndCap = Drawing2D.LineCap.ArrowAnchor
penCroix.Alignment = Drawing2D.PenAlignment.Center
'ligne horizont.
e.Graphics.DrawLine(penCroix, New Point(rectGrille.Left, rectGrille.Top + rectGrille.Height / 2), New Point(rectGrille.Left + rectGrille.Width, rectGrille.Top + rectGrille.Height / 2))
'ligne verticale.
e.Graphics.DrawLine(penCroix, New Point(rectGrille.Left + rectGrille.Width / 2, rectGrille.Top), New Point(rectGrille.Left + rectGrille.Width / 2, rectGrille.Bottom))
penCroix.Dispose()
End Sub
'"tracke" position du cursor sur panel
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
Me.Text = "Coords Panel :" & e.Location.X.ToString & " , " & e.Location.Y.ToString
Me.Text = Me.Text & " Coords Grid :" & (e.Location.X - rectGrille.Top - rectGrille.Width / 2).ToString & " , " & (e.Location.Y - rectGrille.Top - rectGrille.Height / 2).ToString
End Sub
End Class |
Partager