ngalino
Messages postés65Date d'inscriptionsamedi 21 avril 2007StatutMembreDernière intervention15 octobre 2009
-
23 mai 2008 à 08:26
pile_poil
Messages postés682Date d'inscriptionvendredi 6 avril 2007StatutMembreDernière intervention 4 août 2012
-
23 mai 2008 à 11:21
Bonjour,
je developpe avec vb6 et je cherche comment imposer l'aparence des majuscules dans les zonez de texte(textbox); autrement dit, j'aimerais que toute saisie dans un textbox apparaisse en majuscule.
merci de m'aider svp.
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 23 mai 2008 à 08:38
Private Const ES_UPPERCASE As Long = &H8&
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 23 mai 2008 à 10:36
pas si simple... la saisie en sera modifiée (curseur de texte replacé en tête de textbox a chaque fois)
il faut controller:
Private Sub Text3_Change()
Dim nMemSelStart As Long
Dim sBuffer As String
sBuffer = UCase$(Text3.Text)
If Text3.Text <> sBuffer Then
nMemSelStart = Text3.SelStart
Text3.Text = sBuffer
Text3.SelStart = nMemSelStart
End If
End Sub
possible aussi :
Private Sub Text3_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub
mais là, alors, le presse papier devient une faille.
ce que je propose :
Private Const ES_UPPERCASE As Long = &H8&
Private Const GWL_STYLE As Long = -16
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Sub AddWindowStyle(ByRef voControl As Variant, ByVal veStyle As Long)
Dim eStyle As Long
If Not Nothing Is voControl Then
With voControl
eStyle = GetWindowLong(.hwnd, GWL_STYLE)
SetWindowLong .hwnd, GWL_STYLE, eStyle Or veStyle
End With
End If
End Sub
Private Sub Form_Load()
AddWindowStyle Text1, ES_UPPERCASE
End Sub