Board index » cppbuilder » Tchecklistbox and tlistbox

Tchecklistbox and tlistbox


2004-02-16 12:08:38 PM
cppbuilder10
Hi again.
I'm not having much luck with placing two lines of information into one
itemindex within a checklistbox or listbox. I understand I need to use the
OnDrawItem and MeasureItem handlers to display the information. I changed
the rect property to reflect a larger property, etc. What I can't seem to
figure out is how to have it so that when I select the item index I get two
lines selected in one rect(tangle). I hope I make sense... Any ideas where
I can go to research this sort of thing. And, make heads or tails. I
really like the challenge.
Thanks,
Jeff
 
 

Re:Tchecklistbox and tlistbox

"Jeffrey Flindall" < XXXX@XXXXX.COM >wrote in message
Quote
I'm not having much luck with placing two lines of
information into one itemindex within a checklistbox or
listbox.
You need to provide specific details about what exactly does not work for
you.
Quote
I understand I need to use the OnDrawItem and
MeasureItem handlers to display the information.
That is correct.
Quote
I changed the rect property to reflect a larger property, etc.
That is not correct. Using the OnMeasureItem event, you simply set the
desited Height for each item. The TRect provided to the OnDrawText event
will already be the correct dimensions, you do not need to alter it at all.
Quote
What I can't seem to figure out is how to have it so that when I
select the item index I get two lines selected in one rect(tangle).
Perhaps the following code will better help you understand what is needed:
void __fastcall TForm1::ListBox1MeasureItem(TObject *Sender, int Index,
int &Height)
{
RECT r = Rect(0, 0, ListBox1->ClientWidth, 0);
AnsiString Str = ListBox1->Items->Strings[Index];
Height = ::DrawText(ListBox1->Canvas->Handle, Str.c_str(),
Str.Length(), &r, DT_CALCRECT | DT_LEFT | DT_WORDBREAK);
}
void __fastcall TForm1::ListBox1DrawItem(TWinControl* Control, int
Index, const TRect &Rect, TOwnerDrawState State)
{
AnsiString Str = ListBox1->Items->Strings[Index];
TCanvas *pCanvas = ListBox1->Canvas;
if( State.Contains(odSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = ListBox1->Color;
pCanvas->Font->Color = ListBox1->Font->Color;
}
pCanvas->FillRect(Rect);
RECT r = Rect;
::DrawText(pCanvas->Handle, Str.c_str(), Str.Length(), &r, DT_LEFT |
DT_WORDBREAK);
}
ListBox1->Items->Add("Line1\nLine2");
Gambit
 

Re:Tchecklistbox and tlistbox

Sorry for the delay in getting back to you.
I see what I was doing wrong.
My problem was rather simple - that's the complexity!
I had an object containing text information that I wanted to display in the
checklistbox. This information was far to much for a single line entry,
therefore, I wanted to have a mult-line item index. In the code you provided
I see what I was doing wrong. I forgot to place the "\n" newline in with
the listbox1->Items->Add(object /n moreobjectstuff).
Thanks very much for your help.
It's the simple things we stumble on.
Jeff
 

{smallsort}