delphi – 更改特定Checklistbox项的字体或颜色?
发布时间:2020-12-15 04:17:24 所属栏目:大数据 来源:网络整理
导读:我正在使用Delphi XE-3. 我希望更改为核对表框中单个项目的颜色或字体. 这可能吗? 解决方法 您需要使用所有者绘图作为您的检查列表框.将检查列表框的 Style 属性设置为lbOwnerDrawFixed,并为 OnDrawItem 事件编写处理程序.在此事件处理程序中,您可以使用以
我正在使用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; 这是上面例子的结果: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |