I have a subclassed pushbutton and I’d like to change it’s height dynamically at runtime.
I’ve tried both me.height = 28 and self.height = 28 in both the Open and Constructor methods of the subclass, but the button is not resized.
I can resize it during the Open event of the instance, but that’s a pain. It also resizes correctly if I iterate over all the controls during the window.open event and do it using IsA Pushbutton. I’d much rather handle this directly in the subclass though.
I suspect I’m missing something simple. Any ideas?
Seems to work in Xojo 2013r4.1 on Windows 7. I made a pushbutton subclass with height = 40 in its Open event, drug an instance onto the window and set the height in the Inspector to 30. I put a regular pushbutton of height 30 next to it for comparison. Sure enough, when I run the project, my button is bigger.
Coding on OSX 10.8.5 with 2013r4.1. For W32 I’m using a Win7 VM.
Weird, I knew I’d had this subclassing working before so I looked up an old project from last year. It works as expected. The short description is:
a module containing a method called SetPlatformOpts(theControl as Control)
And the relevant snippet from that method:
Case IsA PushButton
if PushButton(theControl).TextFont = "System" then
PushButton(theControl).TextFont = kDefaultTextFont
PushButton(theControl).Height = 32
end if
In the Open event of the PushButton subclass I called SetPlatformOpts(me) and it works as expected.
I don’t know why setting the value directly in the Open event of the subclass in the new project fails. The only thing I can think of that may impact it is the addition of some Einhugur and GraffitiSuite classes.
Imagine you had to manually write the code to layout a window with 1 your custom subclass of push button - called myPushButton
To create all the control it might be something like (note this is very loosely what goes on when the IDE creates the code from the layout you draw in the IDE)
dim pb as new myPushButton // <<<<<<<<< your constructor gets called here
// set properties as laid out by the user in the IDE
pb.setproperties (left, top, width , height) // <<<<<<<<<<<<< what you set in the constructor gets wiped out
So IF you try to set the height & width in the constructor of your subclass they get wiped out on the line AFTER the control is created
Thats why the constructor doesn’t work as you expect
OK so what happens when you use the open event ?
Lets extend our hypothetical code out a bit
dim pb as new myPushButton // <<<<<<<<< your constructor gets called here
// set properties as laid out by the user in the IDE
pb.setproperties (left, top, width , height) // <<<<<<<<<<<<<
// set up the rest of the controls
// ...
// NOW Call their open events
for each control
raise open event on control
next
raise open event on window
so you can see that the settings you put in the IDE get set before your open event would get called and NOW your open even can override them
just try it and put a break point in the open event of your subclass and you’ll see this is whats going on