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 63 64 65 66
| Option Explicit
'***************************** requis pour le TextBox style PlaceHolder ****************
Dim TextFond As String, ColorRech As ColorConstants, ColorText As OLE_COLOR
'***************************************************************************************
Private Sub Form_Load()
'***************************** requis pour le TextBox style PlaceHolder ****************
ColorText = Text1.ForeColor 'Couleur encre du TextBox
ColorRech = vbBlue 'Exemple de couleur encre indicateur de ce que doit faire l'utilisateur du TextBox
TextFond = "Rechercher..." 'Exemple de texte indicateur de ce que doit faire l'utilisateur du TextBox
'initialisation du TextBox
Text1.ForeColor = ColorRech: Text1.Text = TextFond
'***************************************************************************************
Text1.FontBold = True 'option, pour rendre la demonstration plus visible
End Sub
Private Sub Text1_GotFocus()
'***************************** requis pour le TextBox style PlaceHolder ****************
If Text1.ForeColor = ColorRech Then Text1.SelStart = 0
'***************************************************************************************
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
'***************************** requis pour le TextBox style PlaceHolder ****************
If Text1.ForeColor = ColorRech Then Text1.SelStart = 0
'***************************************************************************************
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'***************************** requis pour le TextBox style PlaceHolder ****************
If Text1.ForeColor = ColorRech Then Text1.SelStart = 0
'***************************************************************************************
End Sub
Private Sub Text1_Change()
'***************************** requis pour le TextBox style PlaceHolder ****************
If Len(Text1.Text) = 0 Then Text1.Text = TextFond: Text1.ForeColor = ColorRech: Exit Sub
If (Len(Text1.Text) - Len(TextFond)) = 1 And Text1.ForeColor = ColorRech Then
Text1.Text = Replace(Text1.Text, TextFond, "", , , vbTextCompare)
Text1.ForeColor = ColorText
Text1.SelStart = Len(Text1.Text)
End If
'***************************************************************************************
'----- Ici, pour la demo un exemple simplicte, recherche de la premiere correspondance ------
Dim Deb As Integer
Text2.SelStart = 1: Text2.SelLength = 0 'pour deselectionner la precedante recherche
If Len(Text1.Text) > 2 Then 'limiter le debut de recherche que si au moins 3 caracteres
Deb = InStr(1, Text2.Text, Text1.Text, vbTextCompare)
If Deb <> 0 Then 'quelque chose a été trouvée
Text2.SelStart = Deb - 1: Text2.SelLength = Len(Text1.Text)
End If
End If
'--------------------------------------------------------------------------------------------
End Sub
Private Sub Command1_Click()
'----- Ici, pour la demo un autre exemple simplicte ------
If Text1.ForeColor = ColorRech Then
MsgBox "vous devez renseigner le TextBox" & vbNewLine & "style PlaceHolder", vbCritical, "Non valide"
Else
MsgBox "Merci d'avoir renseigné le TextBox" & vbNewLine & "style PlaceHolder", vbInformation, "Valide"
End If
'--------------------------------------------------------------------------------------------
End Sub |
Partager