gpt4 book ai didi

delphi - 更改特定复选框项目的字体或颜色?

转载 作者:行者123 更新时间:2023-12-03 15:06:19 25 4
gpt4 key购买 nike

我正在使用Delphi XE-3。我希望更改复选框中单个项目的颜色或字体。这可能吗?

最佳答案

您将需要在您的复选框中使用所有者绘图。设置Style将您的复选框的属性设置为 lbOwnerDrawFixed 并编写 OnDrawItem 的处理程序事件。在此事件处理程序中,您可以使用如下内容:

procedure TForm1.CheckListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
Flags: Longint;
begin
with (Control as TCheckListBox) do
begin
// modifying the Canvas.Brush.Color here will adjust the item color
case Index of
0: Canvas.Brush.Color := $00F9F9F9;
1: Canvas.Brush.Color := $00EFEFEF;
2: Canvas.Brush.Color := $00E5E5E5;
end;
Canvas.FillRect(Rect);
// modifying the Canvas.Font.Color here will adjust the item font color
case Index of
0: Canvas.Font.Color := clRed;
1: Canvas.Font.Color := clGreen;
2: Canvas.Font.Color := clBlue;
end;
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
if not UseRightToLeftAlignment then
Inc(Rect.Left, 2)
else
Dec(Rect.Right, 2);
DrawText(Canvas.Handle, Items[Index], Length(Items[Index]), Rect, Flags);
end;
end;

这是上面示例的结果:

enter image description here

关于delphi - 更改特定复选框项目的字体或颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13606562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com