ListBox / focusrect lazarus / 31-LCL ---------------------------------------------------------------------- adc · 2015-10-30 08:56 Hi folks, I can't find out how to remove focusrect on selected item from ListBox, can anyone land an hand? Cheers, M. ---------------------------------------------------------------------- wp · 2015-10-30 10:46 Without the FocusRect, the Listbox would be pretty much useless: The ListBox is a control to select items from a list, and the FocusRect shows the user which item is selected. If you use a Listbox with a different intention then you can owner- draw the items, I think you have full control over painting attributes there. Or you could use a read-only Memo instead of a ListBox. ---------------------------------------------------------------------- bytebites · 2015-10-30 11:20 ListBox1.ItemIndex:=-1; ---------------------------------------------------------------------- wp · 2015-10-30 12:02 But when the user clicks into the list the FocusRect will be back... ---------------------------------------------------------------------- adc · 2015-10-30 13:46 Indeed, ListBox would be useless without a focus, what i ment was, and perhaps i didn't explained it well enough is the lined rect, you know when you use Custom  drawItem and lbOwnderDraw method. I have a listbox with multicolor (background) for items. That is fine and working. Also when itemIndex is changed i draw a rect (FillRect) and selected item receives a focus, that is fine also. What isn't is that there is also a gray hollow rectangle on selected item and that is the one i would like to remove or paint in Fillrect color if possible so it isn't visible.  look at attached picture, that gray rectangle is what i would like to remove somehow. ... i looked at some Delphi questions for the same thing and it mentioned that the value for that particular focus rect is XORed  on original Fillrect color, if i understood articles correctly. But i can't figure out how to turn it off in Lazarus.  Any ideas? ---------------------------------------------------------------------- wp · 2015-10-30 14:13 XOR means that the first paint inverts color, the second paint inverts the inverted colors, i.e. restores the original colors. Therefore, you just have to call DrawFocusrect (a less-known method of TCanvas) a second time to remove the focus rect. This works in Windows where the focus rect is xor-painted (https://stackoverflow.com/questions/28649219/how-to-remove-the- dotted-focus-rectangle-from-tlistbox) - no idea about Linux etc, though: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;  ARect: TRect; State: TOwnerDrawState);begin  with ListBox1.Canvas do begin  if odFocused in State then      Brush.Color := clHighlight else      Brush.Color := clWindow;    FillRect(ARect);    TextOut(ARect.left, ARect.Top, Listbox1.Items[Index]);    if odFocused in State then      DrawFocusRect(ARect);  endend; ---------------------------------------------------------------------- adc · 2015-10-30 14:21 Thanx for replay, Problem is, for "odFocused: i get an error: Identifier not found "odFocused" I am on Mac, perhaps that is a problem?  I am using latest builds of FPC & Lazarus on MacOS Yosemite 10.10. ---------------------------------------------------------------------- wp · 2015-10-30 14:42 Sorry, I forgot: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  LCLType; ---------------------------------------------------------------------- adc · 2015-10-30 14:53 Thanx,  now it did pass & compile but no joy, look ---------------------------------------------------------------------- wp · 2015-10-30 15:19 Ok, I don't have MacOS, so just guessing. Maybe, in the OnDrawItem event handler, set the Listbox1.Canvas.PenStyle to psClear. ---------------------------------------------------------------------- adc · 2015-10-30 15:39 Tried that and with brush bsClear also, same results. Interesting thing though, when ListBox style is lbStandard that rect isn't visible (no custom colors then though). Would it help to search trough unit sources of ListBox and search for lbStandard method to inspect how is it done, or am i missing something else? ---------------------------------------------------------------------- wp · 2015-10-30 15:48 Certainly, you can try, but I am not very optimistic. Maybe you should post your question also in the Lazarus mailing list because many developers do not read the forum. ---------------------------------------------------------------------- adc · 2015-10-30 15:58 OK, i'll try asking in Lazarus mailing list. If you by any chance stumble into solution & it's not too much of a hassle, please drop me a line. Thank you ---------------------------------------------------------------------- adc · 2015-11-01 17:04 ... in the meantime i did some more chacking on wretched focus rect on mac and came to a half-solution. bytebites gave me an idea and it works. If one uses onSelectionChange event to repaint listbox using OnDrawItem method with own color background as marker for current selected item (meaning, repaint your item & background at index as you want it) and then after that sets index to -1 you effectively hide focused rect, leaving the selected item to look the way one wanted. Only thing to keep in mind is you have to track your last selected item index before you set it to -1, otherwise it would be lost in case you need to do something to that specific cell that you just painted. .. hm, hope i explained it well. Method suggested by wp work on Windows, but not on Mac, which obviously has to do something with how mac system handles system color themes. And i would say it would be nice if developers could be so kind to resolve the issue. And for the time being there you have it (; M. ---------------------------------------------------------------------- Bart · 2020-09-12 21:10 I know this is an old post, but I foud it when searching for the same problem. For anyone else googling for it: use lbOwnerDrawFixed and unset lboDrawFocusRect from the listbox options. Bart