CellBackgroundPaint in Subclass not working in DarkMode on Windows 11

I have a Subclass of DesktopListbox in which i’ve added a PaintCellBackground Event.
In this event selected rows will get the Color.Highlight Color as Background Color.
This is working as expected while running my app in light mode.

In dark mode the event is executed but the painting does not happen.
If i use the same code in a non-subclassed listbox, it works as expected again.

Maybe i’m doing something wrong here?

Issue with an example Project: https://tracker.xojo.com/xojoinc/xojo/-/issues/80042

I tried three cases:

  • Default DesktopListbox
  • Subclassed DesktopListbox with event handler in super class
  • Subclassed DesktopListbox with event handler in control itself

listboxes.xojo_binary_project.zip (7.3 KB)

All three work

And my example also works?

Both listboxes should show selected entries with a blue (highlight color) background.
Your image shows the issue i encounter.

The left one is only blue if it has the focus

Exactly. It behaves different from the right one, but it shouldn’t. :slight_smile:

Ah, now I understand.

The left one is the wrong one :smile: .

Yeah, reproducable on my side.

1 Like

Oh no, it isn’t.

You use

Return RaiseEvent PaintCellBackground( g, row, column )

As you don’t return anything in the control in the window the painting is handled by Xojo and not by your code.

Return True and it works

Thank you @StefanA, i see the problem here now. :slight_smile:

How can i make sure the Code in the Subclassed DesktopListbox is respected without me having to add a PaintCellBackground Event in each of my object which use this subclass?

Because i need the Return RaiseEvent PaintCellBackground( g, row, column ) for instances in which i use this subclass but extended it’s functionality in the PaintCellBackground Event and i don’t want to add a Return True i all those instances. And sometimes i need to Return False here, too.

Well, if you want to handle it yourself you have to return true. Otherwise Xojo will handle it.

We use this for such cases:

If Not RaiseEvent PaintCellBackground( g, row, column ) Then

    Return True

End If

So you have the chance to handle it in the control itself.

Otherwise the super class will handle it.

1 Like

Thanks, Stefan. I now understand what the problem is and what I need to do. And I’m glad it’s not a bug. I’ll close my case in the issue tracker.

Have a nice weekend! :slight_smile:

1 Like