2013年9月1日 星期日

Delphi 學習筆記 Listbox 著色

Delphi 學習筆記 Listbox 著色


=============================================================
ListBox  property 中的 style lbOwnerDrawFixed

程式中加這一段

procedure TfrmPhotoDispatch2.ListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var c:Tcanvas;
    l:integer;
    sr:string;
    cr:string;
begin

    c:=Listbox1.Canvas;
    if not (odSelected in state) then
    begin
        sr:=ListBox1.Items[Index];
        l:=Pos(',',sr);
        cr:=copy(sr,l+1,length(s)-l);

        if cr='PFS' then
        begin
              c.Brush.Color:=clgreen;
              c.Font.Color:=clWhite;
              c.FillRect(Rect);
              with Rect do
                c.textout(Left,Top,copy(sr,1,l-1));
        end;

        if cr='CD_PFS' then
        begin
              c.Brush.Color:=clyellow;
              c.Font.Color:=clblue;
              c.FillRect(Rect);
              with Rect do
                c.textout(Left,Top,copy(sr,1,l-1));
        end;

        if cr='OSI_PFS' then
        begin
              c.Brush.Color:=clPurple;
              c.Font.Color:=clWhite;
              c.FillRect(Rect);
              with Rect do
                c.textout(Left,Top,copy(sr,1,l-1));
        end;
    end;

end;

沒有留言:

張貼留言