Option Explicit
Public WithEvents fond1 As MSForms.Label
Public WithEvents fond2 As MSForms.Label
Private Sub fond1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox1.SetFocus
End Sub
Private Sub fond2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox2.SetFocus
End Sub
Private Sub TextBox1_Change()
Controls("Fond_Textbox1").Visible = (Len(TextBox1) = 0)
End Sub
Private Sub TextBox2_Change()
Controls("Fond_Textbox2").Visible = (Len(TextBox2) = 0)
End Sub
Private Sub UserForm_Initialize()
SetFond TextBox1, "Nom", 1
SetFond TextBox2, "Prénom", 2
startupposition = 1
End Sub
Sub SetFond(Ref As Control, Texte_De_Fond As String, ByVal index As Long)
Const Retrait = 10
With Controls.Add("Forms.Label.1", "Fond_" & Ref.Name, True)
.ForeColor = &H80000010
.BackColor = Ref.BackColor
.Font.Name = Ref.Font.Name
.Font.Size = Ref.Font.Size
.Caption = Texte_De_Fond
.AutoSize = True
.Move Ref.Left + Retrait, Ref.Top + (Ref.Height - .Height) / 2
If index = 1 Then
Set fond1 = .Parent.Controls("Fond_" & Ref.Name)
Else
Set fond2 = .Parent.Controls("Fond_" & Ref.Name)
End If
End With
Ref.ZOrder 1
End Sub