Je me suis amusé a faire un exemple avec une étoile et un autre avec un triangle, un rectangle et des lignes croisées:
Option Strict On
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim g As Graphics
Dim _y As Integer = 0 'position Top dans la pictureBox
Dim _x As Integer = 0 'position Left dans la pictureBox
g = PictureBox1.CreateGraphics
' Create pens
Dim greenPen As New Pen(Color.Green, 2)
Dim redPen As New Pen(Color.Red, 2)
' Créons les points qui définissent l'étoile: tourne dans le sens inverse des aiguilles d'une montre.
Dim point1 As New Point(_y + 210, _x) 'A pointe supérieure
Dim point2 As New Point(_y + 165, _x + 100) 'B
Dim point3 As New Point(_y + 50, _x + 100) 'C pointe
Dim point4 As New Point(_y + 150, _x + 170) 'D
Dim point5 As New Point(_y + 100, _x + 280) 'E pointe
Dim point6 As New Point(_y + 210, _x + 220) 'F
Dim point7 As New Point(_y + 320, _x + 280) 'G pointe
Dim point8 As New Point(_y + 280, _x + 170) 'H
Dim point9 As New Point(_y + 350, _x + 100) 'I pointe
Dim point10 As New Point(_y + 250, _x + 100) 'J
Dim ptsArray As Point() = {point1, point2, point3, point4, _
point5, point6, point7, point8, point9, point10}
' Draw polygon
g.DrawPolygon(redPen, ptsArray)
' Dispose
greenPen.Dispose()
redPen.Dispose()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim g As Graphics
Dim _y As Integer = 10 'position Top dans la pictureBox
Dim _x As Integer = 10 'position Left dans la pictureBox
g = PictureBox1.CreateGraphics
' Create pens
Dim redPen As New Pen(Color.Red, 2)
Dim point1 As New Point(_y + 100, _x) 'A pointe supérieure
Dim point2 As New Point(_y, _x + 150) 'B
Dim point3 As New Point(_y + 200, _x + 150) 'C
Dim rect As New Rectangle(_x, _y + 150, 200, 150)
Dim curvePoints As Point() = {point1, point2, point3}
' Draw polygon
g.DrawPolygon(redPen, curvePoints)
g.DrawRectangle(redPen, rect)
'lignes horizontales
g.DrawLine(redPen, _x, _y + 200, 210, 210) '_x = pointleft départ, _y pointTop départ, longueur ligne, fin de ligne Top
g.DrawLine(redPen, _x, _y + 250, 210, 260)
'lignes verticales
g.DrawLine(redPen, _x + 50, _y + 300, 60, 160)
g.DrawLine(redPen, _x + 100, _y + 300, 110, 160)
g.DrawLine(redPen, _x + 150, _y + 300, 160, 160)
' Dispose
redPen.Dispose()
End Sub
End Class
Si l'on veut modifier les points _x et _y par rapport à la PictureBox, voir les différences ici:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim g As Graphics
Dim _y As Integer = 0 'position Top dans la pictureBox
Dim _x As Integer = 0 'position Left dans la pictureBox
g = PictureBox1.CreateGraphics
' Create pens
Dim redPen As New Pen(Color.Red, 2)
Dim point1 As New Point(_y + 100, _x) 'A pointe supérieure
Dim point2 As New Point(_y, _x + 150) 'B
Dim point3 As New Point(_y + 200, _x + 150) 'C
Dim rect As New Rectangle(_x, _y + 150, 200, 150)
Dim curvePoints As Point() = {point1, point2, point3}
' Draw polygon
g.DrawPolygon(redPen, curvePoints)
g.DrawRectangle(redPen, rect)
'lignes horizontales
g.DrawLine(redPen, _x, _y + 200, 200, 200) '_x = pointleft départ, _y pointTop départ, longueur ligne, fin de ligne Top
g.DrawLine(redPen, _x, _y + 250, 200, 250)
'lignes verticales
g.DrawLine(redPen, _x + 50, _y + 300, 50, 150)
g.DrawLine(redPen, _x + 100, _y + 300, 100, 150)
g.DrawLine(redPen, _x + 150, _y + 300, 150, 150)
' Dispose
redPen.Dispose()
End Sub
Voilà bonne programmation
@+ Le Pivert
3 oct. 2016 à 10:26
Je vais appliquer tes conseilles un par un