Nil graphics in Window

Hello everyone,

A property in a window as a graphics used to work but now fails.
g as graphics

Window_Report.g would give a NilObjectException.

Looks like that g was constructed automatically for the window before, but no longer now.
Any ideas?

g is available in the window’s Paint event.

Thank you. Will check Paint event.

If the graphics (Window_Report.g) needs to be manipulated / setup before Paint?

For example, Window_Report.g.foreColor (or DrawingColor) = 0xCFFFFFF
would give the exception.

Trying to construct a local graphics initially with
dim gLocal as new Graphics

would give this error at compile time:

The constructor of this class is protected, and can only be called from within this class
dim gLocal as new Graphics // Testing graphics.

If you want to set something up outside of the paint event, make a property for holding a picture:

Private mBack as Picture

And then you can initialize that in the Opening event:

mBack = Self.BitmapForCaching(self.width, self.height)
Dim g as Graphics =

// do your drawing here

Then in the Paint event:

If mBack <> nil then
    g.drawPicture mBack,0,0
End If

Thank you, Greg O! Will make this change.