Accueil > > > AUTRE PETITE FAQ
AUTRE PETITE FAQ
Information sur la source
Description
C'est une partie de code récupéré là http://www.vbfrance.com/codes/UTILISATION-API-SEND MESSAGE-AVEC-LISTBOX-OU-COMBOBOX_26686.aspx, j'ai choisi "Form15" et ai supprimé les autres.
Bon, ce bout de code est probablement plus complexe que celui que j'ai fait, il pourrait s'adresse aux utilisateurs initiés.
Mais, on arrive pratiquement au même résultat que mon propre code.
Source
- Option Explicit
-
- 'Augmente la taille de la barre de défilement horizontal d'une listbox
- 'si la longueur de texte des éléments ajoutés est plus long que certains éléments
-
- 'http://vbnet.mvps.org/index.html?code/core/sendmessage.htm
-
- Private Const LB_GETHORIZONTALEXTENT = &H193
- Private Const LB_SETHORIZONTALEXTENT = &H194
- Private Const DT_CALCRECT = &H400
- Private Const SM_CXVSCROLL = 2
-
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
-
- Private Declare Function DrawText Lib "user32" _
- Alias "DrawTextA" _
- (ByVal hDC As Long, _
- ByVal lpStr As String, _
- ByVal nCount As Long, _
- lpRect As RECT, ByVal _
- wFormat As Long) As Long
-
- Private Declare Function GetSystemMetrics Lib "user32" _
- (ByVal nIndex As Long) As Long
-
- Private Declare Function SendMessage Lib "user32" _
- Alias "SendMessageA" _
- (ByVal hwnd As Long, _
- ByVal wMsg As Long, _
- ByVal wParam As Long, _
- lParam As Any) As Long
-
- Private Sub Form_Load()
-
- Call AddItemToList(List1, "Ministry of Agriculture and Food")
- Call AddItemToList(List1, "Ministry of the Attorney General")
- Call AddItemToList(List1, "Ministry of Community, City and Social Services")
- Call AddItemToList(List1, "Ministry of Education")
- Call AddItemToList(List1, "Ministry of the Environment")
- Call AddItemToList(List1, "Ministry of Health and Long-Term Care")
- Call AddItemToList(List1, "Ministry of Housing")
-
- End Sub
-
-
- Private Sub Command1_Click()
-
- Dim newIndex As Long
-
- newIndex = AddItemToList(List1, Text1.Text)
-
- 'an 'EnsureVisible' method for the listbox
- List1.TopIndex = newIndex
- Label1.Caption = "Item " & newIndex & " added"
-
- End Sub
-
-
- Private Sub List1_Click()
-
- Text1.Text = List1.List(List1.ListIndex)
-
- End Sub
-
-
- Private Function AddItemToList(ctl As Control, _
- sNewItem As String, _
- Optional dwNewItemData As Variant) As Long
-
- Dim c As Long
- Dim rcText As RECT
- Dim newWidth As Long
- Dim currWidth As Long
- Dim sysScrollWidth As Long
-
- Dim tmpFontName As String
- Dim tmpFontSize As Long
- Dim tmpFontBold As Boolean
-
- 'get the current width used
- If Len(ctl.Tag) > 0 Then
- currWidth = CLng(ctl.Tag)
- End If
-
- 'determine the needed width for the new item
- 'save the font properties to tmp variables
- tmpFontName = FAQ2.Font.Name
- tmpFontSize = FAQ2.Font.Size
- tmpFontBold = FAQ2.Font.Bold
-
- FAQ2.Font.Name = List1.Font.Name
- FAQ2.Font.Size = List1.Font.Size
- FAQ2.Font.Bold = List1.Font.Bold
-
- 'get the width of the system scrollbar
- sysScrollWidth = GetSystemMetrics(SM_CXVSCROLL)
-
- 'use DrawText/DT_CALCRECT to determine item length
- Call DrawText(FAQ2.hDC, sNewItem, -1&, rcText, DT_CALCRECT)
- newWidth = rcText.Right + sysScrollWidth
-
- 'if this is wider than the current setting,
- 'tweak the list and save the new horizontal
- 'extent to the tag property
- If newWidth > currWidth Then
-
- Call SendMessage(List1.hwnd, _
- LB_SETHORIZONTALEXTENT, _
- newWidth, _
- ByVal 0&)
-
- ctl.Tag = newWidth
-
- End If
-
- 'restore the form font properties
- FAQ2.Font.Name = tmpFontName
- FAQ2.Font.Bold = tmpFontBold
- FAQ2.Font.Size = tmpFontSize
-
- 'add the items to the control, and
- 'add the ItemData if supplied
- ctl.AddItem sNewItem
-
- If Not IsMissing(dwNewItemData) Then
- If IsNumeric(dwNewItemData) Then
- ctl.ItemData(ctl.newIndex) = dwNewItemData
- End If
- End If
-
- 'return the new index as the function result
- AddItemToList = ctl.newIndex
-
- End Function
-
Option Explicit
'Augmente la taille de la barre de défilement horizontal d'une listbox
'si la longueur de texte des éléments ajoutés est plus long que certains éléments
'http://vbnet.mvps.org/index.html?code/core/sendmessage.htm
Private Const LB_GETHORIZONTALEXTENT = &H193
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Const DT_CALCRECT = &H400
Private Const SM_CXVSCROLL = 2
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawText Lib "user32" _
Alias "DrawTextA" _
(ByVal hDC As Long, _
ByVal lpStr As String, _
ByVal nCount As Long, _
lpRect As RECT, ByVal _
wFormat As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub Form_Load()
Call AddItemToList(List1, "Ministry of Agriculture and Food")
Call AddItemToList(List1, "Ministry of the Attorney General")
Call AddItemToList(List1, "Ministry of Community, City and Social Services")
Call AddItemToList(List1, "Ministry of Education")
Call AddItemToList(List1, "Ministry of the Environment")
Call AddItemToList(List1, "Ministry of Health and Long-Term Care")
Call AddItemToList(List1, "Ministry of Housing")
End Sub
Private Sub Command1_Click()
Dim newIndex As Long
newIndex = AddItemToList(List1, Text1.Text)
'an 'EnsureVisible' method for the listbox
List1.TopIndex = newIndex
Label1.Caption = "Item " & newIndex & " added"
End Sub
Private Sub List1_Click()
Text1.Text = List1.List(List1.ListIndex)
End Sub
Private Function AddItemToList(ctl As Control, _
sNewItem As String, _
Optional dwNewItemData As Variant) As Long
Dim c As Long
Dim rcText As RECT
Dim newWidth As Long
Dim currWidth As Long
Dim sysScrollWidth As Long
Dim tmpFontName As String
Dim tmpFontSize As Long
Dim tmpFontBold As Boolean
'get the current width used
If Len(ctl.Tag) > 0 Then
currWidth = CLng(ctl.Tag)
End If
'determine the needed width for the new item
'save the font properties to tmp variables
tmpFontName = FAQ2.Font.Name
tmpFontSize = FAQ2.Font.Size
tmpFontBold = FAQ2.Font.Bold
FAQ2.Font.Name = List1.Font.Name
FAQ2.Font.Size = List1.Font.Size
FAQ2.Font.Bold = List1.Font.Bold
'get the width of the system scrollbar
sysScrollWidth = GetSystemMetrics(SM_CXVSCROLL)
'use DrawText/DT_CALCRECT to determine item length
Call DrawText(FAQ2.hDC, sNewItem, -1&, rcText, DT_CALCRECT)
newWidth = rcText.Right + sysScrollWidth
'if this is wider than the current setting,
'tweak the list and save the new horizontal
'extent to the tag property
If newWidth > currWidth Then
Call SendMessage(List1.hwnd, _
LB_SETHORIZONTALEXTENT, _
newWidth, _
ByVal 0&)
ctl.Tag = newWidth
End If
'restore the form font properties
FAQ2.Font.Name = tmpFontName
FAQ2.Font.Bold = tmpFontBold
FAQ2.Font.Size = tmpFontSize
'add the items to the control, and
'add the ItemData if supplied
ctl.AddItem sNewItem
If Not IsMissing(dwNewItemData) Then
If IsNumeric(dwNewItemData) Then
ctl.ItemData(ctl.newIndex) = dwNewItemData
End If
End If
'return the new index as the function result
AddItemToList = ctl.newIndex
End Function
Historique
- 03 juillet 2006 07:22:21 :
- Si vous connaissez bien VB, je suis sûr qu'il n'y aura aucun blème quant au contenu du projet.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Comment copier le contenu d'une listbox ? [ par Rodo22 ]
Bonjour,Admettons que j'ai une liste de trois éléments. Comment puis-je copier la liste dans le presse-papiers ? J'ai essayé avec la commande for...ne
SOS listBox [ par doudou ]
Bonjour,Mon problème est le suivant:Je souhaiterais faire apparaître une zone de liste dans une dia sous powerpoint(cette application doit me permettr
ListBox ordonnée [ par Luke ]
BonjourJ'ai un dbcombo qui est chargé avec une liste de mots pris dans une base de données access 97. Lorsque je clik sur le DBCombo pour faire le cho
Gérer 3 listbox [ par bruno ]
J'ai 3 listbox,avec un liste de noms dans la 1ère.Je voudrais mettre les noms masculins dans la liste 2 et les noms féminins dans la 3.J'ai utilisé la
Envoyer une listbox a un client [ par Frank19 ]
Ce que je veux faire c'est envoyer une listbox a un client ... exemple :TcpServeur(IntMax).SendData lst_user.Listsauf que sa fonctionne pas ...et on l
Comment mettre une image ou pas !! :) [ par scoobydoos ]
Salut,Voila j'ai d'un coté une ListBox et de l'autre une boite Image. Je voudrais quand je clique sur la liste de la ListBox affiché une image (qui a
listbox avec un style = 1 (checkbox) [ par startx25 ]
sous vb5 y'a moyen d'insérer un listbox avec comme style = 1 pour "checkbox" ce qui donne une liste d'élément avec pour chacun un checkbox. le problèm
pb de creation listbox a pl colonnes [ par PDT ]
je voudrais creer une listbox à deux colonnes mais ca ne marche pas mon code est le suivant :liste.columns = 2set db = opendatabase("base.mdb")reqlist
Listbox Doublon aider un new bi [ par bulos ]
Bonjour,J'ai une liste box. J'ai crée un bouton avec le qu'elle l'on peut ajouter le contenu d'une texte box dans la liste box.J'aimerai savoir commen
.::[ Sélectionner automatiquement dans un listbox à choix multiple ]::. [ par bibilafrayeur ]
Bonjour tout le monde.J'ai un listbox don la propriété style est à "checkbox" !!Ce listbox est alimenté par une requete de la manière suivante :<'r
|
Derniers Blogs
[SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson
Logiciels
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 Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.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 LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|