Accueil > > > LIMITER LE NOMBRE DE LIGNES DANS UN TEXTBOX
LIMITER LE NOMBRE DE LIGNES DANS UN TEXTBOX
Information sur la source
Description
J'utilise une API pour compter le nombre de lignes. Il y a plusieurs problématiques : Si une lettre est ajoutée, le code ne s'execute qu'après l'ajout. Mais on ne peut pas supprimer la dernière lettre du texte car l'utilisateur n'était pas forcément à cette position. Il faut donc jouer avec SelStart.
Source
- ' 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
Historique
- 30 janvier 2008 16:19:58 :
- Ajout d'une sub pour éviter le caractère spécial du retour chariot.
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
PAS D'INTELLITRACE SUR MON SITE WEB DANS IIS !PAS D'INTELLITRACE SUR MON SITE WEB DANS IIS ! par Etienne Margraff
J'ai récemment eu un problème pour obtenir l'intelliTrace sur un site web dans IIS. Il n'y avait pas de message d'erreur, rien dans le journal d'évènement Windows, et après 3 appels à une voyante, 2 visites chez un marabou, j'ai failli me résign...
Cliquez pour lire la suite de l'article par Etienne Margraff OFFICE 365 - SHAREPOINT ONLINE, QUELQUES LIMITATIONSOFFICE 365 - SHAREPOINT ONLINE, QUELQUES LIMITATIONS par junarnoalg
De nombreuses entreprises font le choix de SharePoint Online, service fourni au travers de l'offre de Microsoft Office 365. S'il est vrai que ce choix apporte un grand nombre d'avantages; rapidité de mise en œuvre, disponibilité, large couvertu...
Cliquez pour lire la suite de l'article par junarnoalg PRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGEPRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGE par richardc
http://www.c2idotnet.com/articles/presentation-des-api-rest-de-windows-azure-lister-les-comptes-de-storage
Désolé pour "toto", mais c2i existait avant blogs.developpeur.org et c'est mon site "officiel" ;-) ...
Cliquez pour lire la suite de l'article par richardc [HTML5] SLIDES ET DéMOS : AUTOUR DU W3C , NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] SLIDES ET DéMOS : AUTOUR DU W3C , NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Très bonne après-midi passée lors cette conférence avec le W3C, organisée par L' Inria sur les nouveaux standards, ce Mardi 14 Février, on sent vraiment que çà bosse au W3C, et l'avenir est très très prometteur pour le HTML5, notamment ...
Cliquez pour lire la suite de l'article par Gio
Forum
FONCTION EXCEL VBAFONCTION EXCEL VBA par samanta26
Cliquez pour lire la suite par samanta26 RE : VITESSERE : VITESSE par ossama261988
Cliquez pour lire la suite par ossama261988
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|