API1
I cant work out how to do this…
If I create a class that inherits from Listbox
and add a CellTextPaint event to the class
when I set an on-screen listbox to inherit from my class, I get a message to say that the parent has already implemented the event.
How can I resolve that, when I may want the on-screen listbox to do additional things?
Add an Event Definition to your class for CellTextPaint and remember to RaiseEvent CellTextPaint in your Subclasses CellTextPaint Event (bubble the event) so that code runs that you place into the instanced event on the window.
This sounds like a good start, but where does the CODE go?
In an event definition, you cannot enter code,
I cannot rename an event handler in the class.
No need to have another name if you intend to substitute the CellTextPaint event adding some internal preprocessing. You just need RaiseEvent CellTextPaint at the end instead of calling it.
So it would become
add the CellTextPaint EventDefinition to your Listbox subclass. It does nothing here, it just defines a fireable event. No code involved.
Add your handler code for CellTextPaint and RaiseEvent CellTextPaint in that code so it fires the event (that you defined in the step above) to the user of this subclass.
Sorry all. (I don’t have Julian blocked, but…)
Im feeling stupid at the moment, as I don’t quite understand this.
The listbox and class CellTextPaint events clashed in the compile stage if the subclass and actual listbox both had one.
I dont see how this code will resolve that yet.
The stuff the event does needs to return a boolean, doesn’t it?
In the class:
I add an event definition called CellTextPaint , and it has all the usual parameters.
It doesn’t have any code.
I add an event handler. It has all the usual parameters, and it does return a boolean.
IF I add raiseEvent CellTextPaint in that event handler, does that mean I am making the actual listbox execute any code that it contains?
How do I tell the actual listbox that the class did something which requires the return has to be true - there is no boolean parameter?
(Im experimenting now,btw, and may stumble on these answers myself)
Methods are top-down. Event definitions are bottom-up.
If you are in an event like the paint event in a subclass you don’t want to know the parent class being dependent on the subclass. The subclass does the paint, during the paint it tells the parent class to do it’s thing by raising the paint event to the parent and then the subclass finishes the paint.
The code in the subclass looks like:
'some code here
RaiseEvent Paint
'some other code here
That way each class can do what it has to do.
If you want your raised event to return something then declare a return type and use the result:
Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) Handles CellTextPaint as Boolean
// Do some magic here
System.DebugLog "fired "+row.ToString+" , "+column.ToString
Return RaiseEvent CellTextPaint(g, row, column, x, y)
End Function
With my subclassed lisbox with 5 x 3 cells. It just fires once.
btw, just in case anyone is interested, all this work is only because in older Xojo versions on Windows, when I set the color scheme to be high contrast black, checkboxes in a list box cannot be seen. (black on black)
I’ve spent months making my own dark mode stuff, and this is the last thing: a checkbox replacement.
(For reasons, I can’t use anything after Xojo 2018 on Windows in this project due to the changes made in the graphics engines , so Xojo2021R3 doesn’t solve that for me.)