2008. augusztus 22., péntek

How to change the color of the selection in a TCheckListBox


Problem/Question/Abstract:

How to change the color of the selection in a TCheckListBox

Answer:

If you want to change the color of the selection so that it's always the Color property, this code will work:

procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with Control as TCheckListBox do
  begin
    { Use the default colors regardless of selection status }
    Canvas.Font.Color := Font.Color;
    Canvas.Brush.Color := Color;
    { Erase everything there at the moment }
    Canvas.FillRect(Rect);
    { Draw the text }
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése