Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub DrawACircle(ByRef g As Graphics, ByRef center As Point, ByVal radius As Integer)
' Select a pen object and make it red
Dim pn As New Pen(Color.Red)
' Create a bounding rectangle and make its center the center of our point
' Then make its width 2 * the radius
' Then draw our ellipse
Dim rect As New Rectangle(center.X / 2, center.Y / 2, radius * 2, radius * 2)
g.DrawEllipse(pn, rect)
End Sub
et tu l utilise comme ceci :
DrawCircle(e.Graphics, new Point(100,100), 50)
Dim x As Integer = 10
Dim y As Integer = 10
Dim wid As Integer = 150
Dim hgt As Integer = 75
e.Graphics.SmoothingMode = _
Drawing2D.SmoothingMode.AntiAlias
e.Graphics.DrawRectangle(Pens.Black, x, y, wid, hgt)
y += hgt + 10
e.Graphics.DrawEllipse(Pens.Black, x, y, wid, hgt)
y += hgt + 10
e.Graphics.DrawLine(Pens.Black, x, y, x + wid, y + hgt)
y = 10
x += wid + 10
e.Graphics.DrawArc(Pens.Black, x, y, wid, hgt, -30, 270)
y += hgt + 10
e.Graphics.DrawPie(Pens.Black, x, y, wid, hgt, -30, 270)
y += hgt + 10
Dim big_font As New Font("Comic Sans MS", 60, _
FontStyle.Bold, GraphicsUnit.Pixel)
e.Graphics.TextRenderingHint = _
TextRenderingHint.AntiAliasGridFit
e.Graphics.DrawString("Hello!", big_font, _
Brushes.Black, x, y)
Dim centreX As Double = 10
Dim centreY As Double = 20
Dim apen As New Pen(Color.White, 1)
Dim radius As Double = 60
Const Pi As Double = Math.PI
Dim x1, y1 As Integer
For num As Double = 0 To 2 * Pi Step 0.01
x1 = Convert.ToInt32(radius * Math.Cos(num) + centreX)
y1 = Convert.ToInt32(radius * Math.Sin(num) + centreY)
e.Graphics.DrawLine(apen, x1, y1, x1 + 1, y1)
Next
' En début de Module ou de Class Option Explicit On Imports System.Drawing ' Ensuite par exemple pour une fenêtre Form avec un Button Public Class Form1 Public G As Graphics ' ou Public G As System.Drawing.Graphics ' (c est la même chose) Public Sub New() ' Cet appel est requis par le Concepteur Windows Form. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). G = Me.CreateGraphics 'Pour un formulaire Me.DoubleBuffered = True Me.WindowState = FormWindowState.Maximized end sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Affiche_Exemple(G) End Sub ..... etc
Option Explicit On Imports System.Drawing Module Module1 Public Sub Affiche_Exemple(ByRef G As System.Drawing.Graphics) Dim x As Integer = 10 Dim y As Integer = 10 Dim wid As Integer = 150 Dim hgt As Integer = 75 G.SmoothingMode = _ Drawing2D.SmoothingMode.AntiAlias G.DrawRectangle(Pens.Black, x, y, wid, hgt) y += hgt + 10 G.DrawEllipse(Pens.Black, x, y, wid, hgt) y += hgt + 10 G.DrawLine(Pens.Black, x, y, x + wid, y + hgt) y = 10 x += wid + 10 G.DrawArc(Pens.Black, x, y, wid, hgt, -30, 270) y += hgt + 10 G.DrawPie(Pens.Black, x, y, wid, hgt, -30, 270) y += hgt + 10 Dim big_font As New Font("Comic Sans MS", 60, _ FontStyle.Bold, GraphicsUnit.Pixel) G.TextRenderingHint = _ TextRenderingHint.AntiAliasGridFit G.DrawString("Hello!", big_font, _ Brushes.Black, x, y) end Sub End Module
Option Explicit On
Imports System.Drawing
Public Class DemoTraces
' Document à imprimer
Private WithEvents _doc As New Printing.PrintDocument
' Fenêtres d'aperçu avant impression et de choix d'imprimante
Private WithEvents _prv As New PrintPreviewDialog()
Private _parametresImpression As Printing.PrinterSettings
#Region " Tracé "
Private Sub ButtonTracer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonTracer.Click
Me.TraceTest.Show()
' --- tracé : un cercle
Dim tc1 As TraceCercle = New TraceCercle(400, 300, 200, Pens.LightGray)
With Me.TraceTest
.StockerTrace(tc1)
End With
End Sub
Public Sub ButtonTracer_Click(ByRef G As System.Drawing.Graphics)
Dim x As Integer = 10
Dim y As Integer = 10
Dim wid As Integer = 150
Dim hgt As Integer = 75
G.SmoothingMode = _
Drawing2D.SmoothingMode.AntiAlias
G.DrawRectangle(Pens.Black, x, y, wid, hgt)
y += hgt + 10
G.DrawEllipse(Pens.Black, x, y, wid, hgt)
y += hgt + 10
G.DrawLine(Pens.Black, x, y, x + wid, y + hgt)
y = 10
x += wid + 10
G.DrawArc(Pens.Black, x, y, wid, hgt, -30, 270)
y += hgt + 10
G.DrawPie(Pens.Black, x, y, wid, hgt, -30, 270)
y += hgt + 10
Dim big_font As New Font("Comic Sans MS", 60, _
FontStyle.Bold, GraphicsUnit.Pixel)
'G.TextRenderingHint = _
'TextRenderingHint.AntiAliasGridFit()
'G.DrawString("Hello!", big_font, _
'Brushes.Black, x, y)
End Sub
#End Region
Option Explicit On Imports System.Drawing Public Class DemoTraces ' Document à imprimer Private WithEvents _doc As New Printing.PrintDocument ' Fenêtres d'aperçu avant impression et de choix d'imprimante Private WithEvents _prv As New PrintPreviewDialog() Private _parametresImpression As Printing.PrinterSettings Public G As System.Drawing.Graphics Public Sub New() ' Cet appel est requis par le Concepteur Windows Form. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). G = Me.CreateGraphics 'Pour un formulaire Me.DoubleBuffered = True Me.WindowState = FormWindowState.Maximized end sub #Region " Tracé " Private Sub ButtonTracer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonTracer.Click Me.TraceTest.Show() ' --- tracé : un cercle Dim tc1 As TraceCercle = New TraceCercle(400, 300, 200, Pens.LightGray) With Me.TraceTest .StockerTrace(tc1) End With Affiche_Exemple(G) End Sub Public Sub Affiche_Exemple(ByRef G As System.Drawing.Graphics) Dim x As Integer = 10 Dim y As Integer = 10 Dim wid As Integer = 150 Dim hgt As Integer = 75 G.SmoothingMode = _ Drawing2D.SmoothingMode.AntiAlias G.DrawRectangle(Pens.Black, x, y, wid, hgt) y += hgt + 10 G.DrawEllipse(Pens.Black, x, y, wid, hgt) y += hgt + 10 G.DrawLine(Pens.Black, x, y, x + wid, y + hgt) y = 10 x += wid + 10 G.DrawArc(Pens.Black, x, y, wid, hgt, -30, 270) y += hgt + 10 G.DrawPie(Pens.Black, x, y, wid, hgt, -30, 270) y += hgt + 10 Dim big_font As New Font("Comic Sans MS", 60, _ FontStyle.Bold, GraphicsUnit.Pixel) G.TextRenderingHint = _ TextRenderingHint.AntiAliasGridFit G.DrawString("Hello!", big_font, _ Brushes.Black, x, y) end Sub #End Region
Imports System.Drawing
Public Class Accueil
Private g As Graphics
Private Sub Accueil_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
g = e.Graphics
g.DrawArc(Pens.Black, 10, 10, 100, 100, 0, 90)
End Sub
End Class
Dim big_font As New Font("Comic Sans MS", 60, _
FontStyle.Bold, GraphicsUnit.Pixel)
G.TextRenderingHint = _
TextRenderingHint.AntiAliasGridFit()
G.DrawString("Hello!", big_font, _
Brushes.Black, x, y)
System.Drawing.Text, juste pour rire.
Pen.
#Region " Tracé "
Private Sub ButtonTracer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonTracer.Click
Me.TraceTest.Show()
' --- tracé : un cercle
Dim tc1 As TraceCercle = New TraceCercle(400, 300, 200, Pens.LightGray)
Affiche_Exemple(G)
Dim x As Integer = 10
Dim y As Integer = 10
Dim wid As Integer = 100
Dim hgt As Integer = 150
G.SmoothingMode = _
Drawing2D.SmoothingMode.AntiAlias
G.DrawRectangle(Pens.Black, x, y + 500, wid, hgt)
y += hgt + 10
With Me.TraceTest
.StockerTrace(tc1)
End With
End Sub
'Dim big_font As New Font("Comic Sans MS", 60, _
'FontStyle.Bold, GraphicsUnit.Pixel)
'G.TextRenderingHint = _
'TextRenderingHint.AntiAliasGridFit()
'G.DrawString("Hello!", big_font, _
'Brushes.Black, x, y)
Imports System.Drawing
Imports System.Drawing.Text
Public Class Accueil
Private g As Graphics
Private Sub Accueil_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
g = e.Graphics
g.DrawArc(Pens.Black, 10, 10, 100, 100, 0, 90)
g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
End Sub
End Class
Public Class Accueil
Private g As Graphics
Private Sub Accueil_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
g = e.Graphics
g.DrawArc(Pens.Black, 10, 10, 100, 100, 0, 90)
g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
End Sub
End Class
With Me.TraceTest
.StockerTrace(tc1)
End With
TraceTesta été créé, et quel est son type. Ne serait-ce pas un contrôle
PictureBox?