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
|
Public Class Form1
Private img As Bitmap = Nothing
Private topleft As Point
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.AutoScroll = True 'assure le defilement du panel
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
topleft = New Point(800, 600)
Dim txtYear As String = Date.Now.Year.ToString()
Dim rect As New Rectangle(0, 0, 1200, 800)
img = New Bitmap(rect.Width, rect.Height)
Me.Panel1.Size = img.Size 'panel est ajuste pour afficher la totalité de l'image
Using grfx As Graphics = Graphics.FromImage(img)
Using fnt As New Font("Times New Roman", 240, FontStyle.Bold)
Dim sizeString As SizeF = grfx.MeasureString(txtYear, fnt)
'rectangle de presentation
Dim layout As New Rectangle(topleft, Size.Ceiling(sizeString))
' on decale l'img quelque soit la taille du string
If layout.Right > img.Width Then
layout.X -= layout.Right - img.Width
End If
If layout.Bottom > img.Height Then
layout.Y -= layout.Bottom - img.Height
End If
grfx.FillRectangle(Brushes.Aquamarine, rect)
grfx.DrawString(
txtYear,
New Font("Times New Roman", 240, FontStyle.Bold),
New SolidBrush(Color.Black),
layout)
'dessin du rectangle de presentation
Using thepen As New Pen(Brushes.Red, 2.0)
grfx.DrawRectangle(thepen, layout)
End Using
End Using
End Using
Me.Panel1.Invalidate()
End Sub
Private Sub Panel1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim gr As Graphics = e.Graphics
If img Is Nothing Then Return
gr.DrawImage(img, 0, 0)
End Sub
End Class |
Partager