Bonjour j'aimerai faire en sorte que la scrollbar soit toujours visible dans un tlistbox afin de pouvoir calculer la valeur reel du clientrect au moment de l'event Onmesureitem.

voici le code que j'utilise à titre d'info
le probleme c'est que le clientrect obtenu lors de onmesureItem est basé sur les dimensions de la listbox sans le scrollbat, et dans le ListBox1DrawItem, le client rect est celui basé sur les dimensions avec la scrollbar, ce qui cree des probleme de dimension sur certaines chaines.

donc je cherche un moyen, soit d'afficher toujours la scrollbar, soit d'obtenir les bonnes valeurs a chaque coup

merci



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
procedure TSearchForm.ListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
   bmp:tbitmap;
begin
	with(Control as TListBox).Canvas do  {Le dessin se fait sur le canevas du contrôle,pas dans la fiche }
	begin
      FillRect(Rect);{efface le rectangle }
      {bitmap>>>}
      bmp:=tbitmap.create;
      imagelist1.getbitmap(6,bmp);
      bmp.Transparent :=True;
      bmp.TransParentColor :=bmp.canvas.pixels[0,0];
      bmp.TransparentMode :=tmAuto;
      Draw(Rect.Left+2,Rect.Top,bmp);
      bmp.free;
      {<<<bitmap}
      inc(Rect.left,20);
      Dec(Rect.Right, 5);
      Drawtext(listbox1.Canvas.Handle,
               PChar(listbox1.Items[Index]),
               length(listbox1.Items[Index]),
               Rect,
               DT_WORDBREAK + DT_EDITCONTROL);
      //DrawText(listbox1.Canvas.Handle, PChar(listbox1.Items[Index]), -1, rect, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
	end;
end;
 
procedure TSearchForm.ListBox1MeasureItem(Control: TWinControl;
  Index: Integer; var Height: Integer);
var
  s: string;
  R: TRect;
begin
   R := listbox1.ClientRect;
   inc(R.left,20);
   Dec(R.Right, 5);
   S := listbox1.Items[Index];
   listbox1.Canvas.Font.Assign(listbox1.Font);
   Height := DrawTextEx(listbox1.Canvas.Handle,
                        PChar(s),
                        length(s),
                        R,
                        DT_WORDBREAK or DT_CALCRECT or DT_EXTERNALLEADING,
                        nil);
   Inc(Height, 4);
end;