Drawing on parent window from TextField?

Is this doable?

I have a custom TextField class, and depending on what I enter in the TextField I want to draw outside the TextField on the window.

I know I could use it in a ContainerControl but I wonder if it is possible to keep all the code in the TextField class.

Thanks for any insights you can share.


I take it this is more complex than implementing the Text changed Event handler?



Well, if you know how to do it all in the TextChange event then I‘d love to know how …

how do you expect to draw to the graphics of the window outside its paint event since thats not possible any more ?
ie/ textchange cant access the graphics of the containing window to draw to it

would seem the only decent way would be to have the window call a method in your text field during the windows paint event that would allow the text field to draw into the window graphics

What about drawing an Offscreen Picture that is then displayed in the window graphics ? (or in a Canvas’ Backdrop) ?

Thanks all. I have now implemented it in three different ways:

(1) use the Window.paint event, iterate over all TextFields, and paint something there

(2) add a draw method to the custom TextField class, pass g to it from the Window’s paint event, and move the drawing code there

(3) make a ContainerControl and use the Paint event of the ContainerControl

They all work fine though I will go with the ContainerControl as it is the most encapsulated.

I had wondered if there was another way but couldn’t think of one so I thought I’d ask.

Thanks all for your efforts!


I guess I didn’t follow your question. You seem to have found your own way, but what about making the window an observer of the control? Probably more work than what you’re doing though.

That would not solve the problem of how to give the TextField access to the Window‘s graphics context for drawing. It would still require the same amount of code in addition to setting up an observer pattern as far as I can see.

A simpler solution would be to draw into the backdrop picture.

Tried that first before asking the question using Self and TrueWindow. Didn‘t work (NilObjectException).

I get the application crash and the IDE crashed too; I do not saved the few code lines…

Michel’s idea seems to work ok, I don’t know why you got a NOE.


You need to create the picture and affect it to the window backdrop before you can address it.

[quote=434204:@]Michel’s idea seems to work ok, I don’t know why you got a NOE.


Thanks. That project crashed for me too, but that got me on the right track: after emptying my cache and restarting the computer it now works as expected. My Mac usually runs for weeks or even months and only restarts for rare system updates … and I keep forgetting that if I run Xojo for a long time then it can get itself into a weird state.

still you have to be careful with backdrop

if this were a control to be wrapped up and given to others and someone had their own backdrop on a window then you’ve drawn on that backdrop - possibly in a way that is not reversible

and that could be a problem

The other possibility is to draw to a picture, and display it in Paint. Then just an invalidate will show changes.