Canvas issue

Hi everyone. I’m just a “hobbiest” programmer learning Xojo. I have a problem that bewilders me and wondering if anyone has any thoughts.
I’m just delving into canvases and how to use them to create a more versatile “list” box (alternating colours etc). Now, I’ll try and explain as best I can - I have a tab control with about 5 tabs. On the first tab (0) I have several controls including a list box in the upper left quarter with several columns and rows etc). On the 4th tab (3) I then have a canvas control taking up the entire area. On this I am creating the list box I mentioned where multiple lines of info are displayed.

All is good EXCEPT, when I first open the app it starts on the first tab and then, when I first click on the 4th tab, with the canvas control, an outline of the list box from tab 0 is clearly seen drawn in the canvas. If I click away and come back, it is gone and all is as expected. I have tried and tried different things but cannot, for the life of me, figure out what is happening - does anyone have any thoughts? Is it something lacking in my understanding (probably!) or is there a Xojo bug of some sort I am unaware of.

Anyway, sorry this is so long and I hope it is detailed enough to explain the issue - any help, GREATLY appreciated.


uncheck the “usefocusring” property of the listbox on the first tab.

also you can have alternate colors in a listbox subclass by writing, in the CellBackgroundPaint event of the listbox :

if mHasAlternateRowBackColor then if row mod 2 = 0 then g.ForeColor=&cD3FCFF00 g.FillRect 0,0,g.Width, g.Height end if end if g.ForeColor=&c00000000
assuming mHasAlternateRowBackColor is a boolean property of the listbox.

Jean-Yves, Thank you so much for that! It’s done the trick :slight_smile:

Thanks also for the other tip re the alternating colours, I actually did already know that one. What I need tho, is a way to have the actual text in different colours, so if anyone knows how to achieve that I would like to know, but my understanding is it can’t be done with Xojo’s list boxes.

Anyway, again, thanks for the answer :slight_smile:


Where do you get that “info”???

Of course you can do that. Look at CellTextPaint.

+1 with Marcus, you can do a lot of things with celltextpaint (and cellbackgroundpaint)

You can do whatever you want in terms of color inside the CelTextPaint event. This will make text red, for instance :

Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) Handles CellTextPaint as Boolean g.ForeColor = &cFF0000 End Function

And before you ask, you can set some text styles from there (Bold, Italic).

For some uses, you may have (or not) to add an ending Return True (…) at the end of the Event.

Thanks everyone, I’ll look into these.
Markus, it may have been a misunderstanding from me, but I was reading an article from xDev magazine a few months ago about how to use list boxes from Cocoa with the main reason, I thought, that xojo’s was very limited. But, I’ll definitely look into it again.

Thanks again.

The Xojo listbox IS limited, but not in the ways you have described. You can do a lot with it.

Thanks everyone. You’ve got me on the right track - really appreciate it :slight_smile: