Custom Class/Control with containing a Canvas

  1. 2 weeks ago

    I have created a subclassed ListBox that has the events and properties I want.
    It also uses a custom canvas which I'd like to have as part of the custom ListBox class, but I can't seem to cut/paste the canvas from the Main Window to have it as "part" of the Custom ListBox. It accesses the custom Listbox's properties so I'd like it to be part of the subclass.
    How would I do this?
    Hopefully I'm making sense.

  2. Norman P

    Sep 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog
    Edited 2 weeks ago

    classes cannot contain other classes

    however there are alternatives I've discussed on my blog

  3. Thank you. Makes for some messy code, but so it goes!

  4. Norman P

    Sep 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog

    put the listbox & canvas in a module
    make the listbox global
    make the canvas private
    then the listbox can create instances of that canvas but nothing outside the module can

    that _should_ do it

    its about as close as you get

  5. Ivan T

    Sep 6 Pre-Release Testers
    Edited 2 weeks ago

    @Andy B I have created a subclassed ListBox that has the events and properties I want.
    It also uses a custom canvas which I'd like to have as part of the custom ListBox class, but I can't seem to cut/paste the canvas from the Main Window to have it as "part" of the Custom ListBox. It accesses the custom Listbox's properties so I'd like it to be part of the subclass.
    How would I do this?
    Hopefully I'm making sense.

    Why dont you use a container and put both, the listbox and the canvas on it. It is a lot less messy code

  6. Norman P

    Sep 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog

    just then to make the container act like a listbox you have to expose a ton of the methods on the container, plus the events etc

    been there done that and it can work but its a lot of work

  7. Ivan T

    Sep 6 Pre-Release Testers
    Edited 2 weeks ago

    @Norman P just then to make the container act like a listbox you have to expose a ton of the methods

    Naaaaa, no need of manually expose methods and properties...

    Container.Listbox.Whatever

    @Norman P plus the events ... its a lot of work

    Actually quite easy, just right click on any event of the listbox, click on Create Event Definition from Event. Done!, 2 clicks

    If he es not making a comercial product, there is no case to "over-engineer" the code

  8. Norman P

    Sep 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog

    @Ivan T Naaaaa, no need of manually expose methods and properties...

    Container.Listbox.Whatever

    Whether or not this is for personal or commercial use I would never recommend this style
    Encapsulate things properly and then you can, if you want, change the internal implementation without affecting anything that uses this. Not doing so makes that job much harder if you ever want to do it.

    And not doing it can make for some nasty unmaintainable code regardless of what you plan to do long term

  9. Dave S

    Sep 6 San Diego, California USA

    A custom control should appear to your app as any other control....with a specific set of events, properties and methods
    Any embedded control should be private and invisible to the outside world.

  10. Ivan T

    Sep 6 Pre-Release Testers
    Edited 2 weeks ago

    @Dave S A custom control should appear to your app as any other control.

    Shure, rules are there for something ;-)

    https://www.youtube.com/watch?v=yijQRhPvJhQ

  11. Norman P

    Sep 7 Pre-Release Testers, Xojo Pro great-white-software.com/blog

    Not a rule - just a "good habit" to get into
    It makes no difference to me if you write your own software that way
    I try not to so the components I make are something I ca neasily lift into any other app
    Heck I've written listbox replacements that have much nicer behaviour for headers etc
    And, because my container control appears to be a listbox in every respect, it has the exact same API plus extra methods, events and properties, it can be easily substituted for the built in listbox

  12. Julen I

    Sep 7 Europe

    In the particular case of wanting a canvas in a listbox, wouldn't it be an option to use the cellbackgroundpaint event in the listbox as canvas?

    You wouldn't be able to use your custom canvas, of course.

    Julen

or Sign Up to reply!