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
|
Imports System.ComponentModel
Public Class CustomLabel
Inherits Label
Private m_text As String
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'Assigne l'espacement ligne par defaut
Me.m_lineSpacing = Me.Font.Height - Me.Font.GetHeight
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaint(e)
'Ajoutez ici votre code de dessin personnalisé
Dim lblText As String = Me.Text
Dim arrayString() As String = Split(lblText, vbCrLf)
Dim g As Graphics = e.Graphics
Dim font As Font = Me.Font
Dim brush As Brush = New SolidBrush(Me.ForeColor)
Dim lineSpacing As Double = Me.LineSpacing
Dim size As SizeF = g.MeasureString("A", font)
Dim pos As Double = 0.0F
For numLine As Integer = 0 To arrayString.Length - 1
Dim lineToDraw As String = arrayString(numLine)
g.DrawString(lineToDraw, font, brush, 0.0F, pos)
pos = pos + size.Width + lineSpacing
Next
End Sub
<Browsable(True)> _
Public Overrides Property Text() As String
Get
Return m_text
End Get
Set(ByVal value As String)
m_text = value
Me.Invalidate()
End Set
End Property
Private m_lineSpacing As Double
<Browsable(True)> _
Public Property LineSpacing() As Double
Get
Return m_lineSpacing
End Get
Set(ByVal value As Double)
If value <= 0 Then
m_lineSpacing = Me.Font.Height - Me.Font.GetHeight
Else
m_lineSpacing = value
End If
Me.Invalidate()
End Set
End Property
End Class |
Partager