Default Properties for a control

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Default Properties for a control

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:19 pm

by Torrie Moore >> Sun, 10 Oct 1999 20:11:49 GMT

I'm trying to set a default property for a control. I have used the windowCreated method to set the property but am finding that I cannot change the property value as the default is set every time the control is used. I tried the create method, but the value does not appear in painter. Can anyone help?

Torrie Moore
Concept Engineering

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Default Properties for a control

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:19 pm

by Joseph O'Dwyer >> Sun, 10 Oct 1999 20:57:31 GMT

Torrie,

You can use the isInPainter method of the control and only set the default values if this returns true in the windowCreated method.

Joseph O'Dwyer
BMIS

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Default Properties for a control

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:19 pm

by Craig Shearer >> Mon, 11 Oct 1999 20:37:49 GMT

Hi Torrie

You should use the create method to set default values for controls when they are painted in the Painter. I think the problem you were having is that you were perhaps adding a create method after you'd painted the control. The create method is only called once, which is when you first paint the control on the form.

You can set default values in the create method which can then be overridden by using the property sheet in the Painter.

Conversely, you could use the windowCreated method, but as you've discovered it gets called each time you open the form in the Painter and each time you show the form in your application. So, setting default values in the windowCreated method is only appropriate if you don't want to keep the settings overridden in the Painter, which I suspect is not what you want.

Another interesting point, you can set the default size of a control in the create method. So, you could have a standard size for buttons. Then, if you paint the control on the form by just dropping it on (ie. click the control button on the control palette, then single click on the form, rather than dragging a size) the default size will work. This is useful if you want to have a standard size for say button controls.

Craig.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 28 guests