Recent

Author Topic: [Solved] TlistView doesn't show Icons when I use CustomDrawItem  (Read 4489 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 827
    • Blog personal
Hello If I change the color of the Font, during the CustomDrawItem event, the ListView doesn't show the Icon, the listview are flashing, the icons with the names appears a disapper very fast.

This is my code in CustomDrawItem:
Code: Pascal  [Select][+][-]
  1. With Item.SubItems.Objects[0] as TSignalType do
  2.   Begin
  3.     If TypeOfSignal = 'DI' Then
  4.        Sender.Font.Color := clred
  5.     else
  6.         Sender.Font.Color := clblue;
  7.  
  8.    DefaultDraw:=True;
  9.   end;
  10. end;                    
  11.  

If in the above code I add a condition to do nothing when the listview is in Icon style (vsIcon), you can see the Icons with the names and the icons perfect.
for example
Code: Pascal  [Select][+][-]
  1.  If lsvEntradasSalidas.ViewStyle = vsIcon Then
  2.  Begin
  3.  Sender.Font.Color:=clBLue;
  4.  end
  5.  Else
  6.  Begin
  7.  
  8.    With Item.SubItems.Objects[0] as TSignalType do
  9.   Begin
  10.     If TypeOfSignal = 'DI' Then
  11.        Sender.Font.Color := clred
  12.     else
  13.         Sender.Font.Color := clblue;
  14.  
  15.    DefaultDraw:=True;
  16.   end;
  17.  end;                          
  18.  
I use W7/64  bits, and Lazarus 1.0 RC1.

is this a bug?, what am I doing wrong?.

Any idea?

Thanks

/blueicaro
« Last Edit: August 26, 2012, 01:49:57 pm by BlueIcaro »

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: TlistView doesn't show Icons when I use CustomDrawItem
« Reply #1 on: August 24, 2012, 08:43:39 pm »
Custom Draw events you don't change the Font property of the Control, but the Font property of the Canvas.  If you change the Font of the Control you'll be getting thousands of FontChange events firing.

Try doing  Sender.Canvas.Font.Color instead..

To save doing lots of Sender.Canvas, etc, I normally create a TCanvas pointer.

eg.
Code: [Select]
var
  c:TCanvas;
begin
  c := Sender.Canvas;
  c.Font.Color := clRed;
end;

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: TlistView doesn't show Icons when I use CustomDrawItem
« Reply #2 on: August 24, 2012, 09:23:07 pm »
I can't use CustomDrawn controls because they have no BiDiMode support so far, so I have not really tried them to see what benefit they have.  I'm sure if I do try them I will find some nice things.  But for now, I use the standard Lazarus controls on Windows 7-64.  Turning Themes off gives me almost the same visual effect.

If KpjComp's method fails, you might try using a standard TListView with Themes turned off.  But Mr. KpjComp's methods almost always work perfectly, so that's should be your first choice.

To turn Themes off, go to Project/Project Options and uncheck 'Use manifest file...'.
Lazarus Trunk / fpc 2.6.2 / Win32

BlueIcaro

  • Hero Member
  • *****
  • Posts: 827
    • Blog personal
Re: TlistView doesn't show Icons when I use CustomDrawItem
« Reply #3 on: August 26, 2012, 12:43:38 pm »
Hi, Avishay and KpjComp, thanks for yours answers, and excuseme, because I didn't have time to came back to the forum.

As you said, KPjComp, I create a Tcanvas pointer, and now it's works nice, here is the new code:
Code: Pascal  [Select][+][-]
  1. var
  2.   C: TCanvas;
  3. begin
  4.  
  5. C:= Sender.Canvas;
  6.  
  7. With Item.SubItems.Objects[0] as TSignalType do
  8.   Begin
  9.     If TypeOfSignal = 'DI' Then
  10.        C.Font.Color := clred
  11.     else
  12.         C.Font.Color := clblue;
  13.  
  14.    DefaultDraw:=True;
  15.   end;        
  16.  
Avishai, you said, that you use standard controls. I don't understand you. I used a TListview droped from the comun tab controls.
Where can I find standard controls, as you said?.

/BlueIcaro

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: TlistView doesn't show Icons when I use CustomDrawItem
« Reply #4 on: August 26, 2012, 01:10:50 pm »
Sorry.  My mistake.  In your header it said "CustomDrawItem" and I thought you were talking about the "CustomDrawn" components.  I haven't looked at them for a while so I thought they had added a ListView to "CustomDrawn".
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018