Recent

Author Topic: How to draw text in TListView.onCustomDrawSubItem  (Read 4422 times)

zamtmn

  • Hero Member
  • *****
  • Posts: 675
How to draw text in TListView.onCustomDrawSubItem
« on: October 23, 2012, 11:51:46 am »
I'm currently using

Code: [Select]
DefaultDraw:=false;
textrect:=Item.DisplayRectSubItem(SubItem,drLabel);
DrawText(TCustomListView(sender).canvas.Handle,@s[1],length(s),textrect,DT_LEFT or DT_VCENTER);

The text appears a few pixels above. How to make the text on the level with the defaultdraw items?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to draw text in TListView.onCustomDrawSubItem
« Reply #1 on: October 23, 2012, 12:19:18 pm »
try DT_LEFT or DT_BOTTOM as the last parameter?

zamtmn

  • Hero Member
  • *****
  • Posts: 675
Re: How to draw text in TListView.onCustomDrawSubItem
« Reply #2 on: October 23, 2012, 12:23:06 pm »
Without result, looks the same

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to draw text in TListView.onCustomDrawSubItem
« Reply #3 on: October 23, 2012, 12:34:40 pm »
Perhaps you'll just have to hack, and adjust textrect a few pixels manually with InflateRect or similar.

zamtmn

  • Hero Member
  • *****
  • Posts: 675
Re: How to draw text in TListView.onCustomDrawSubItem
« Reply #4 on: October 23, 2012, 12:42:50 pm »
But I would like the decision to work on all platforms and themes

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: How to draw text in TListView.onCustomDrawSubItem
« Reply #5 on: October 24, 2012, 01:23:12 pm »
Maybe you calculate the rectangle too small. Test with Canvas.Rectangle, or the like. If so, DrawText has an option to measure boundaries: DT_CALCRECT.
And perhaps you could check functions in unit themes as well.
Lazarus 1.7 (SVN) FPC 3.0.0

zamtmn

  • Hero Member
  • *****
  • Posts: 675
Re: How to draw text in TListView.onCustomDrawSubItem
« Reply #6 on: October 24, 2012, 02:40:14 pm »
No, rectangle is good.
Quote
DrawText(TCustomListView(sender).canvas.Handle,@s[1],length(s),textrect,DT_LEFT or DT_SINGLELINE or DT_VCENTER);
or
Code: [Select]
ts:=TCustomListView(Sender).Canvas.TextStyle;
ts.Layout:=tlCenter;
TCustomListView(sender).canvas.TextRect(textrect,textrect.Left,0,s,ts);
looks good in win32, but text much lower in gtk2

>>And perhaps you could check functions in unit themes as well.
Thanks, I will look
« Last Edit: October 24, 2012, 02:44:54 pm by zamtmn »

 

TinyPortal © 2005-2018