Contour de couleur texte

Contenu du snippet

Ajouter un contour de couleur à un texte.
Contour simple et contour bicolor:

Option Strict On
Imports System.Drawing.Drawing2D
Public Class Form1
    Private Sub Contour(ByVal texte As String, ByVal police As String, ByVal size As Integer, ByVal taille As Integer, ByVal pen As SolidBrush, ByVal couleur As SolidBrush, ByVal x As Integer, ByVal y As Integer, ByVal pic As PictureBox)
        Dim useFont As Font = New Font(police, size)
        Dim MyPen As New Pen(pen, taille)
        Dim g As Graphics = pic.CreateGraphics()
        Dim p As New GraphicsPath()
        p.AddString(texte, useFont.FontFamily, FontStyle.Bold, size, New Point(x, y), StringFormat.GenericDefault)
        g.FillPath(couleur, p) ' couleur texte
        g.DrawPath(MyPen, p) 'couleur contour
        g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
        g.SmoothingMode = SmoothingMode.AntiAlias
        p.Dispose()
        p = Nothing
    End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Contour("Mon texte", "Comic Sans MS", 80, 5, CType((Brushes.Blue), SolidBrush), CType((Brushes.Yellow), SolidBrush), 10, 30, PictureBox1)
        '        'texte ,     police,   taille texte, taille pen,      couleur pen,                  couleur texte,  position x et y, pictureBox
    End Sub
    Private Sub Contour_bicolor(ByVal texte As String, ByVal police As String, ByVal size As Integer, ByVal taille As Integer, ByVal pen As SolidBrush, ByVal pen_2 As Color, ByVal couleur As SolidBrush, ByVal x As Integer, ByVal y As Integer, ByVal pic As PictureBox)
        Dim useFont As Font = New Font(police, size)
        Dim MyPen As New Pen(pen, taille)
        Dim MyPen_2 As New Pen(pen_2, taille) '2 ème couleur contour
        MyPen_2.Color = pen_2 '2 ème couleur contour
        MyPen_2.DashStyle = DashStyle.Dot 'point
        Dim g As Graphics = pic.CreateGraphics()
        Dim p As New GraphicsPath()
        p.AddString(texte, useFont.FontFamily, FontStyle.Bold, size, New Point(x, y), StringFormat.GenericDefault)
        g.FillPath(couleur, p) ' couleur texte
        g.DrawPath(MyPen, p) 'couleur contour
        g.DrawPath(MyPen_2, p) '2 ème couleur contour
        g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
        g.SmoothingMode = SmoothingMode.AntiAlias
        p.Dispose()
        p = Nothing
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Contour_bicolor("1 2 3 4 5", "Arial", 100, 3, CType((Brushes.Yellow), SolidBrush), Color.Red, CType((Brushes.LightBlue), SolidBrush), 10, 30, PictureBox2)
        '               'texte  police,taille texte, taille pen, couleur pen,   2 ème couleur contour            couleur texte,       position x et y, pictureBox
    End Sub
End Class


voir exemple ici:

http://codes-sources.commentcamarche.net/source/101526-tirage-du-loto

Bonne programmation

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.