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
| Public Class TonLabel
Inherits Label
Public Enum modeFormatage
MODE_DEFAULT = 0
MODE_MAJUSCULE = 1
MODE_PREMIERE_LETTRE_MAJUSCULE = 2
End Enum
Private _modeFormat As modeFormatage
Public Property modeFormat As modeFormatage
Get
Return _modeFormat
End Get
Set(value As modeFormatage)
_modeFormat = value
End Set
End Property
Public Sub New()
MyBase.New()
modeFormat = modeFormatage.MODE_DEFAULT
End Sub
Private Function formaterText(Chaine As String) As String
If Chaine <> String.Empty Then
Select Case modeFormat
Case modeFormatage.MODE_DEFAULT
'Rien à faire
Case modeFormatage.MODE_MAJUSCULE
Chaine = Chaine.ToUpper()
Case modeFormatage.MODE_PREMIERE_LETTRE_MAJUSCULE
Chaine = Chaine.Substring(0, 1).ToUpper & Chaine.Substring(1, Chaine.Length)
Case Else
Throw New System.Exception("Non implémenté")
End Select
End If
Return Chaine
End Function
Private Sub TonLabel_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
Me.Text = formaterText(Me.Text)
End Sub
End Class |