Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Frustrations:Tchecklistbox compontent

Status
Not open for further replies.

Roel

Programmer
Jul 19, 2000
1
NL
Hello there,<br>I've got a problem with a Checklistbox. I want to create a list in which users can check lines. If a line is checked the font of ONLY that line needs to be changed. For example the line must be striked out (fsStrikeout). This is like the list of taskrequests in Outlook.<br>I can not manage to change the font for a single line. It seems that it is only possible to change to Font for the total checklistbox. Is there any solution for this problem, or maybe any other component I can use with the posibilty to change fonts for single lines?<br>Thanks in advance.<br><br>Kindest Regards,<br>Roel Bartels
 
Hi!<br><br>Set the property TCheckListBox.Style to lbOwnerDrawFixed and then set event handler on TCheckListBox.OnDrawItem:<br><br>procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;<br>&nbsp;&nbsp;Index: Integer; Rect: TRect; State: TOwnerDrawState);<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if CheckListBox1.Checked[Index] then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckListBox1.Canvas.Font.Style:=[fsStrikeOut];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckListBox1.Canvas.TextRect(Rect,Rect.left,Rect.top,CheckListBox1.Items[Index])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckListBox1.Canvas.Font.Style:=[];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckListBox1.Canvas.TextRect(Rect,Rect.left,Rect.top,CheckListBox1.Items[Index]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>but if user click on checkbox that line dont repaint. This, for example, can be done like:<br><br>procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);<br>var rect : TRect;<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with CheckListBox1 do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rect:=ItemRect(ItemIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rect.Left:=15;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckListBox1DrawItem(CheckListBox1,ItemIndex,rect,[]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>This is an TCheckListBox.OnClickCheck handler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top