[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need help with custom component.

Posted on 2006-04-10
2
Medium Priority
?
185 Views
Last Modified: 2010-05-18
I'm having trouble with a custom listbox component(does not descend form tlistbox or tcustomlistbox), basically I want text normal when not selected and bold when the item is selected. However it is always bold for some reason.

I believe the problem lies in the component source as opposed to my code below but here it is anyway.

Basically umm in the OnDrawItem event I do this:

Procedure TFrmMain.MP3_ListDrawItem(Sender: TObject; ACanvas: TCanvas; Index: SmallInt; Const ARect: TRect; Selected: Boolean);
Begin
 If (Selected) Then ACanvas.Font.Style := [fsBold]
 Else ACanvas.Font.Style := [];
    ACanvas.Brush.Style := bsClear;
    ACanvas.TextOut(ARect.Left,ARect.Top,TCListBox(Sender).Items[Index]);
End;

But the text is always bold whether selected or not. Here isa link to the source of the component if anyone wants to check it out themselves and see what may be wrong. I must be missing something but all looks fine to me.

http://chessoscorner.com/files/CListBox.zip
0
Comment
Question by:Chesso
2 Comments
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 465 total points
ID: 16417916
I tested and it worked fine.

Procedure TFrmMain.MP3_ListDrawItem(Sender: TObject; ACanvas: TCanvas; Index: SmallInt; Const ARect: TRect; Selected: Boolean);
Begin
 If (Selected) Then ACanvas.Font.Style := [fsBold]
 Else ACanvas.Font.Style := [];
    ACanvas.Brush.Style := bsClear;
//you don't need this line
//    ACanvas.TextOut(ARect.Left,ARect.Top,TCListBox(Sender).Items[Index]);
End;

You probably forgot to assign the event to the component, e.g.

  CListBox1.OnDrawItem:= MP3_ListDrawItem;

regards
Pierre
0
 

Author Comment

by:Chesso
ID: 16422333
Nope the event was assigned but removing the textout and placing the setting of bsClear in only the else statement fixes it up.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question