Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

AUTRE PETITE FAQ


Information sur la source

Catégorie :Message Box Classé sous : liste, repères, marqueurs, sélections, listbox Niveau : Initié Date de création : 02/07/2006 Date de mise à jour : 03/07/2006 07:22:20 Vu / téléchargé: 4 766 / 206

Note :
1 / 10 - par 1 personne
1,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

Description

Cliquez pour voir la capture en taille normale
C'est une partie de code récupéré là http://www.vbfrance.com/codes/UTILISATION-API-SENDMESSAGE-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

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

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.

Commentaires et avis

signaler à un administrateur
Commentaire de jack le 02/07/2006 23:29:08 administrateur CS

Salut
Et ta source sert à quoi ?
Quel est son intérêt ?
Qu'as tu réussi à faire ?
Explique mieux pourquoi tu es content du résultat ...

signaler à un administrateur
Commentaire de DARKSIDIOUS le 03/07/2006 08:23:23 administrateur CS

Quel est l'intérêt de passer par les API pour rajouter un texte dans une listbox ???

Les API c'est bien, mais faut quand même pas les utilser partout, sinon autant programmer en C !

DarK Sidious

signaler à un administrateur
Commentaire de muad-dib le 03/07/2006 14:25:59

Encore une source qui sert à rien

Ajouter un commentaire

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


Nos sponsors

Sondage...

CalendriCode

Décembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,499 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.