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:

  1. set style property of list box lbownerdrawfixed.
  2. 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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -