A simple TListView OwnerDraw font font example and color?

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

When I try to change Canvas.font.color, and that all I have is no problem.

If I set canvas.font.size, I found that the size of the text drawn by the control does not change.

If I try to capture a picture of the text, from within OnCustomDrawItem, I find that I cannot. I know how to use OnCustomDraw to draw in the background area, but I want the user to draw a listview list item so that I can set the font color and name and font size of the text.

I know that there are some problems with using Canvas in the context of drawing the owner of a ListView 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; 
+4
source share
1 answer

I had a similar problem with TDBGrid.

Try calling Canvas.Refresh after reassigning the Canvas.Font properties.

+10
source

Source: https://habr.com/ru/post/1399431/


All Articles