delphi - Change color of ListBox Item when Clicked on this Item -
so have listbox on form, consists of different links, of them blue , underlined (like html links, know). when user clicks 1 of items(links), opens in default browser, want particular link change color purple. here's have in onclick procedure now:
procedure tform1.listbox1click(sender: tobject); begin shellexecute(handle, 'open', pansichar(listbox1.items[listbox1.itemindex]), nil, nil, sw_shownormal); end;
your problem boils down how draw list different fonts settings each item. need following:
- set
style
property of list boxlbownerdrawfixed
. - handle
ondrawitem
event of list box draw each item.
your ondrawitem
event draw item in font indicate whether or not item has been clicked already. can manage logic presume. show simple example draws items differently depending on index
of item.
procedure tform1.listbox1drawitem(control: twincontrol; index: integer; rect: trect; state: townerdrawstate); var listbox: tlistbox; canvas: tcanvas; begin listbox := control tlistbox; canvas := listbox.canvas; // clear destination rectangle canvas.fillrect(rect); // prepare font style , color canvas.font.style := [fsunderline]; if odd(index) canvas.font.color := clblue else canvas.font.color := clpurple; // draw text canvas.textout(rect.left, rect.top, listbox.items[index]); // , focus rect if odfocused in state canvas.drawfocusrect(rect); end;
Comments
Post a Comment