Bonjour,
Est il possible d'augmenter l'espacement entre les lignes d'un listbox ?
Merci
Bonjour,
Est il possible d'augmenter l'espacement entre les lignes d'un listbox ?
Merci
voir la faq : http://c.developpez.com/faq/vc/?page...istBoxDrawItem
Ce qui est affirmé sans preuve peut être nié sans preuve Euclide.
Les conversions numériques en C,C++,C++/CLI
DLL d'extensions : écriture d'un plug-in de classe
Démarrer avec les MFC 2/2
Création d'un ActiveX MFC
Intégration d'une imprimante PDF pour éditions automatisées
Migrer du code de Visual C++ 6.0 vers Visual C++ 2005
Démarrer avec les MFC sous Visual C++1/2
la Faq Visual C++ 500 Q/R,Mon blog
Aide en Ligne MFC
Cours et tutoriels C++ - FAQ C++ - Forum C++.
Merci et désolé, j'avais pas eu le reflexe FAQ.
Par contre, j'ai implémenté le code de la faq, permettant de modifier l'affichage (ton lien) couplé à un m_lbListbox.SetItemHeight(0, 50); dans le OnInitDialog,
L'affichage est bon si ce n'est que l'ascensceur vertical n'apparait pas alors que la liste dépasse.
Il n'apparait pas non plus quand on sélectionne a la souris les items, on ne le vois que lorsque l'on descente / monte au clavier la selection dans la liste
Comment forcer l'ascenseur à s'afficher si la liste dépasse ?
merci
A priori, le probleme est du à m_lbListbox.SetItemHeight(0, 50);.
Partant de ce support microsoft j'ai donc comme classe :
Ici, l'ascenseur fonctionne correctement, seulement, comme j'augmente la taille dans le onitdialog avec m_lbListbox.SetItemHeight(0, 50);, le premier élement apprait nickel, mais les suivant ont la taille par defaut et non la nouvelle definie.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 #include "StdAfx.h" #include ".\mylistbox.h" CMyListBox::CMyListBox(void) { p_iAlign = DT_LEFT | DT_VCENTER; CListBox::CListBox(); } CMyListBox::~CMyListBox(void) { CListBox::~CListBox(); } void CMyListBox::SetLineAlign(UINT iAlign){ p_iAlign = iAlign; } void CMyListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX); LPCTSTR lpszText=NULL ; CString str; // si le style est <> de LBS_HASSTRINGS on considère que la valeur à afficher //est dans ItemData. if(lpDrawItemStruct->itemID!=CB_ERR && !(GetStyle() & LBS_HASSTRINGS)) lpszText=(LPCTSTR) lpDrawItemStruct->itemData; else { // Récupération de la chaîne grâce à l'index stocké dans ItemID. GetText(lpDrawItemStruct->itemID,str); lpszText= str; } ASSERT(lpszText != NULL); CDC dc; dc.Attach(lpDrawItemStruct->hDC); // Save these value to restore them when done drawing. COLORREF crOldTextColor = dc.GetTextColor(); COLORREF crOldBkColor = dc.GetBkColor(); // If this item is selected, set the background color // and the text color to appropriate values. Also, erase // rect by filling it with the background color. if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); // couleur du texte dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT)); // couleur de fond // Petit cadre rouge CBrush br(RGB(255, 0, 0)); dc.FrameRect(&lpDrawItemStruct->rcItem, &br); // En cas de sélection, on reduit la zone ou le texte peut etre écris lpDrawItemStruct->rcItem.top++; lpDrawItemStruct->rcItem.left++; lpDrawItemStruct->rcItem.right--; lpDrawItemStruct->rcItem.bottom--; } else dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor); // Draw the text. dc.DrawText( lpszText, strlen(lpszText), &lpDrawItemStruct->rcItem, p_iAlign|DT_SINGLELINE); // Reset the background color and the text color back to their // original values. dc.SetTextColor(crOldTextColor); dc.SetBkColor(crOldBkColor); dc.Detach(); } void CMyListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { static int cyItem=-1; //Height of a listbox item if (-1 == cyItem){ CFont* theFont; CDC* theDC; TEXTMETRIC tm; /* * Attempt to get the font of the dialog. However, * on the first attempt in the life of the dialog, * this could fail; in that case use the system font. */ if ((theFont = GetParent()->GetFont()) == NULL) theFont = theFont->FromHandle((HFONT)::GetStockObject(SYSTEM_FONT)); theDC = GetParent()->GetDC(); theFont = theDC->SelectObject(theFont); /* * Item height is the maximum of the font height and the * bitmap height. We know that all bitmaps are the same * size, so we just get information for one of them. */ theDC->GetTextMetrics(&tm); cyItem=tm.tmHeight; GetParent()->ReleaseDC(theDC); } // Return Result lpMeasureItemStruct->itemHeight = cyItem; }
snif .... m_lbListbox.SetItemHeight(0, 50);
Evidemment ! l'item 0 à la bonne taille !
Il me reste a trouver un SetItemHeight qui le fasse pour tous directement
bon, ben jsuis passé en "owner draw" à fixe, et la ... par magie... l'ascenseur est bien la, mais pas avec la bonne taille.... jusqu'à ce que l'on scroll
:S
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager