Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

delphi - Simple TListView OwnerDraw Text Font Size and Color example?

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I experienced a similar issue on TDBGrid.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...