Est il possible d'aligner à droite ou de centrer les textes d'une TComboBox plutôt que d'avoir l'alignement à gauche 'standard' ?
merci pour vos réponses!
Langage Borland C++ 6 et/ou Delphi
Version imprimable
Est il possible d'aligner à droite ou de centrer les textes d'une TComboBox plutôt que d'avoir l'alignement à gauche 'standard' ?
merci pour vos réponses!
Langage Borland C++ 6 et/ou Delphi
A moins d'utiliser le style ownerdraw (dans ce cas on fait absolument ce qu'on veut), je ne crois pas que ce soit possible.
J'ai écris la macro
puis appelé cette macro depuis l'event 'OnDrawItem'Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #define RightJustify(T,Indx,Rect) \ { \ if ( Indx >= T->Items->Count) return; \ if ( Indx <0 ) return; \ AnsiString Text; \ int TextWidth, TextHeight, RectHeight; \ T->Canvas->FillRect(Rect); \ Text= T->Items->Strings[Indx]; \ Rect.Right -= 2; \ TextWidth= T->Canvas->TextWidth(Text); \ TextHeight= T->Canvas->TextHeight(Text); \ RectHeight= Rect.Bottom - Rect.Top; \ T->Canvas->TextOut(Rect.Right-TextWidth,Rect.Top + (RectHeight-TextHeight)/2,Text);\ }
Ceci fonctionne pour TComboBox (Style = csOwnerDrawFixed) etCode:
1
2
3
4
5
6 void __fastcall TAboutBox72::Fichier_lst_1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) RightJustify(Fichier_lst_1,Index,Rect) // Common.h
TListBox ( style = lbOwnerDrawFixed )
mais n'est pas très rapide si les listes sont longues.