Board index » cppbuilder » DrawItem not called in class derived from TCustomListBox

DrawItem not called in class derived from TCustomListBox


2008-06-14 05:08:26 AM
cppbuilder50
Hello Everyone,
I am trying to implement a listbox control derived from
TCustomListBox.
Header:
Quote
//---------------------------------------------------------------------------
class PACKAGE TResiDebugOutput : public TCustomListBox
{
private:
protected:
virtual void __fastcall DrawItem(int Index,
const Types::TRect &Rect, Windows::TOwnerDrawState State);
public:
__fastcall TResiDebugOutput(TComponent* Owner);
__published:
__property Align;
__property Items;
};
Source:
Quote
//---------------------------------------------------------------------------
void __fastcall TResiDebugOutput::DrawItem(int Index,
const Types::TRect &Rect, Windows::TOwnerDrawState State)
{
AnsiString Line = Items->Strings[Index];
if (Line.Pos("[ERR]"))
{
Canvas->Font->Color = clRed;
}
else
{
Canvas->Font->Color = clSilver;
}
TCustomListBox::DrawItem(Index, Rect, State);
}
When I place my control onto a form it still gets painted the old
standard way.
However when I click the control in the form editor and drag it around
my DrawItem
method is called (Error messages are drawn in red color). But then and
only then.
So for some reason my method is only called when I drag the control
around in
the form editor. Seems like very strange behaviour to me...
My version: CodeGear C++Builder 2007 R2 Version 11.0.2987.10779
Any Ideas?
Thanks for any comments,
Martin
 
 

Re:DrawItem not called in class derived from TCustomListBox

I made some screenshots to further explain my problem.
First screen shows the control placed on a form:
www.student.tugraz.at/mmoerth/vcl/bad.png
Second screen shows the control when dragged with the mouse
(still in the form editor):
www.student.tugraz.at/mmoerth/vcl/good.png
Thanx again for any help!
Martin
 

Re:DrawItem not called in class derived from TCustomListBox

I solved the problem!
My mistake was that I did not set the Style property of my control to
lbOwnerDrawFixed.
Stupid, right? :-)
 

{smallsort}