简单的TListView OwnerDraw文本字体大小和颜色示例? [英] Simple TListView OwnerDraw Text Font Size and Color example?

查看:451
本文介绍了简单的TListView OwnerDraw文本字体大小和颜色示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以拥有4列的报表模式,以 OnCustomDrawItem 的方式绘制列表视图控件。



当我尝试改变Canvas.font.color,这就是我所做的,我没有问题。



如果我设置了canvas.font.size,我发现控件的文字大小没有变化。



如果我尝试接管文字的绘画,从OnCustomDrawItem中我发现我不能。我知道如何使用OnCustomDraw绘制在背景区域,但是我想自定义绘制一个listview ITEM,以便我可以设置文本的颜色和字体名称和字体大小。



我知道在ListView所有者绘制的上下文中使用Canvas有一些问题,以及在ListView中可以做的一些限制。

 程序TForm1.MyListViewCustomDrawItem(发件人:TCustomListView; 
项目:TListItem;状态:TCustomDrawState; var DefaultDraw:Boolean);
begin
Sender.Canvas.Font.Size:= 13; // 没有效果。
Sender.Canvas.Font.Color:= clRed; // WORKS。
Sender.Canvas.Font.Style:= Sender.Canvas.Font.Style + [fsBold]; // WORKS!
结束


解决方案

我在TDBGrid上遇到了类似的问题。 >

在重新分配Canvas.Font属性后尝试调用 Canvas.Refresh


I am trying to owner draw a List View control in report-mode with 4 columns, using OnCustomDrawItem.

When I try to change the Canvas.font.color, and that's all I do, I have no problems.

If I set canvas.font.size, I find that there is no change in the size of the text drawn by the control.

If I try to take over the painting of the text, from within OnCustomDrawItem, I find I can not. I am aware of how to use OnCustomDraw to draw in the background area, but I want to custom draw a listview ITEM, so that I can set the color and font name and font size of the text.

I know that there are some problems with using Canvas in the context of ListView owner draw, and some limitations of what you can do in a ListView.

procedure TForm1.MyListViewCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
    Sender.Canvas.Font.Size := 13; // NO effect.
    Sender.Canvas.Font.Color := clRed; // WORKS.
    Sender.Canvas.Font.Style  :=Sender.Canvas.Font.Style + [fsBold]; // WORKS!
end;

解决方案

I experienced a similar issue on TDBGrid.

Try to call Canvas.Refresh after you reassign the Canvas.Font properties.

这篇关于简单的TListView OwnerDraw文本字体大小和颜色示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆