IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

augmenter l'espacement dans un listbox


Sujet :

MFC

  1. #1
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut augmenter l'espacement dans un listbox
    Bonjour,

    Est il possible d'augmenter l'espacement entre les lignes d'un listbox ?

    Merci

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323

  3. #3
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut
    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

  4. #4
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut
    A priori, le probleme est du à m_lbListbox.SetItemHeight(0, 50);.

    Partant de ce support microsoft j'ai donc comme classe :

    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;
    }
    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.

  5. #5
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut
    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

  6. #6
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut
    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

Discussions similaires

  1. Réponses: 9
    Dernier message: 06/11/2007, 12h36
  2. [Access] Nom d'une table avec un espace dans SQL
    Par Corsaire dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/04/2006, 15h50
  3. Icône a coté du texte dans une ListBox
    Par joce3000 dans le forum C++Builder
    Réponses: 6
    Dernier message: 05/12/2003, 02h25
  4. [debutant] preservation des espace dans un fichier xml
    Par Eric B dans le forum XML/XSL et SOAP
    Réponses: 7
    Dernier message: 03/09/2003, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo