DrawInto crashes in the celltextpaint event

When you add the below code in a listbox celltextpaint event it hard crashes the app.
Is this a known issue?

button1.drawinto(g,10,10)

The button1 is a generic button added outside the window.

I don’t know why it crashes, first I’ve heard of it. But a workaround is to DrawInto a Picture then DrawPicture that to g.

Yes, that does work but it results in a blurred button when enabling HDPi.
It is not possible to make the button twice as big, then draw it into the picture and display it half size (which is how you normally would draw a ‘sharp’ image in HDPi).

Any other ideas?

Make sure you create the picture with BitmapForCaching and I bet the blurriness goes away.

You know, a button is not exactly the Sistine Chapel. Take a screen shot of a button without caption in HiDPI, and use that instead. Drawing the caption is really easy to do.

That is also a way to do this. But the DrawInto is much more flexible and you can very easily have all the original state behaviours without creating several images.

OK, I looked at this but not sure how to use this. Any pointers?

EDIT: Nevermind. Found how to do this and it works perfect.

I just tested and it works. go1Button is a PushButton on the window.

Function CellTextPaint(g As Graphics, ....) as Boolean dim p As Picture = BitmapForCaching(go1Button.Width, go1Button.Height+2) go1Button.DrawInto( p.Graphics, 0, 0 ) g.DrawPicture( p, 0, 0 ) End Function

Yeah, and it is pretty cool to draw controls in a canvas, listbox, …
No need to make your own ‘fake’ images anymore. And the best thing is, it uses the correct native look depending on which OSX/macOS version you use.
I am happy to discover this DrawInto method … didn’t know it existed. :slight_smile:

Is there a way to trigger the original button to capture other states of the control?

For a PushButton a declare to highlight is working for me to capture it’s pressed state. This is the code in go2Button.

[code]Sub Action()

declare sub highlight lib “AppKit” selector “highlight:” (id As integer, h As Boolean)

highlight( go1Button.Handle, true )

dim p As Picture = BitmapForCaching( go1Button.Width+10, go1Button.Height+10 )
go1Button.DrawInto( p.Graphics, 5, 5 )
Canvas1.Backdrop = p

highlight( go1Button.Handle, false )

End Sub[/code]

Thats neat!
That should also work with a PopupMenu … very helpful.