- ' Appel à l'API et déclarations
- Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
- (ByVal hWnd As Long, _
- ByVal wMsg As Long, _
- ByVal wParam As Long, _
- ByVal lParam As Long) As Long
-
- Private Const EM_NOMBRELIGNE = &HBA
-
- ' Si l'ajout de texte fait dépasser les 4 lignes, on supprime les caractères en trop.
- Private Sub Textbox1_Change()
- If (SendMessageLong(Textbox1.hWnd, EM_NOMBRELIGNE, 0&, 0&) > 4) Then
- If Textbox1.SelStart > 0 Then
- Textbox1.SelStart = Textbox1.SelStart - 1
- Textbox1.SelLength = 1
- Textbox1.SelText = ""
- End If
- End If
- End Sub
-
- ' Si l'utilisateur fait un retour chariot alors qu'il y a 4 lignes, un caractère spécial apparait, ce code l'évite.
- Private Sub Textbox1_KeyPress(KeyAscii As Integer)
- If (SendMessageLong(Textbox1.hwnd, EM_NOMBRELIGNE, 0&, 0&) = 4) And (KeyAscii = 10 Or KeyAscii = 13) Then
- KeyAscii = 0
- End If
- End Sub
' Appel à l'API et déclarations
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const EM_NOMBRELIGNE = &HBA
' Si l'ajout de texte fait dépasser les 4 lignes, on supprime les caractères en trop.
Private Sub Textbox1_Change()
If (SendMessageLong(Textbox1.hWnd, EM_NOMBRELIGNE, 0&, 0&) > 4) Then
If Textbox1.SelStart > 0 Then
Textbox1.SelStart = Textbox1.SelStart - 1
Textbox1.SelLength = 1
Textbox1.SelText = ""
End If
End If
End Sub
' Si l'utilisateur fait un retour chariot alors qu'il y a 4 lignes, un caractère spécial apparait, ce code l'évite.
Private Sub Textbox1_KeyPress(KeyAscii As Integer)
If (SendMessageLong(Textbox1.hwnd, EM_NOMBRELIGNE, 0&, 0&) = 4) And (KeyAscii = 10 Or KeyAscii = 13) Then
KeyAscii = 0
End If
End Sub