Bonjour a tous,
Je chercher a centrer le texte d'un 'Item' dans une listbox lors de OnDrawItem (en fonction de cas précis).
J'ai essayé :
Cela fonctionne a peu pres mais on ne peut pas dire que cela soit centré a 100 %, donc finalement pas térrible...
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 void __fastcall TFVierge::NListBoxDrawItem(TWinControl *Control, int Index, const TRect &Rect, TOwnerDrawState State) { TCanvas *pCanvas = ((TListBox *)Control)->Canvas; if ((Index%2)==0) pCanvas->Brush->Color = clSilver; TField *pField; switch (FVierge->ModeFiche[0]) { case 'R': pField = FVierge->NTable->Fields->Fields[3]; break; case 'C': pField = FVierge->NTable->Fields->Fields[4]; break; } if (pField->AsString.operator ==(((TListBox *)Control)->Items->Strings[Index])) { pCanvas->Brush->Color = clCream; pCanvas->FrameRect(Rect); pCanvas->Font->Color = clRed; } else { if(State.Contains(odSelected)) { pCanvas->Brush->Color = clCream; pCanvas->FillRect(Rect); pCanvas->Font->Color = clMaroon; } else { pCanvas->FillRect(Rect); } } //C'est la que commence mon sujet ... if (pField->AsString.operator ==(((TListBox *)Control)->Items->Strings[Index])) { int LTexte = ((TListBox *)Control)->Items->Strings[Index].Length(); int DTexte = (Rect.Width() - LTexte) * 0.50; pCanvas->TextOut(DTexte,Rect.Top+1, ((TListBox *)Control)->Items->Strings[Index]); } else { pCanvas->TextOut(Rect.Left+5,Rect.Top+1, ((TListBox *)Control)->Items->Strings[Index]); } }![]()
Je pense que c'est parceque je 'compare' Strings[].Length() et Rect.Width(), enfin je crois (j'ai l'intuition que ce n'est pas tout a fait semblable).
Comment puis je faire pour centrer parfaitement le texte ?
D'avance merci pour vos conseils (et bon dimanche...)
Partager