Constructor Issue

I have a custom button with a Constructor. For some reason, none of the default colors in the Constructor are recognized when a new instance of the button is created. Instead, the button is black. Any ideas as to what is causing this behavior?

Thanks!

The Constructor:

> // Calling the overridden superclass constructor.
> Super.Constructor
> 
> // Set default colors
> NormalGradientStartColor = &cCBBFB3
> NormalGradientEndColor = &cA3978B
> HoverGradientStartColor = &cDFD7D0
> HoverGradientEndColor = &cB9AFA6
> ClickedGradientStartColor = &c8E8379
> ClickedGradientEndColor = &c6B625A
> TextColor = Color.Black
> ClickedTextColor = &cFFE7CD
> ButtonText = "Button" // Default button text
> 
> // Set other initial states if needed
> buttonState = "Normal"

How does the rest of your code look like?

try what happens if you set the default colors in the properties itself. (are they all black?)

do you create the button at runtime or was it placed at a window?
are this properties public and maybe saved from designer?

everthing that change the ui need a .Refresh so its good to use computed properties.

Hey, guys/gals. Thanks for the replies. But I’ll have to revisit this issue later as something else just took priority. :grinning:

If your button’s constructor has a parameter, Xojo will ignore that constructor when you drag and drop an instance of the button on a Window.

Workaround:
Copy the color assignments in a public method you can name SetDefaults

Update your constructor to call SetDefaults

In the button’s Opening event in the Window, add the following code:
me.SetDefaults

2 Likes

Unusual properties probably needing a more complex code (gradients in Xojo buttons?)

I think that the community need a more complete sample with only this button to try to understand (and maybe fix) the problem.

Jeremie, my constructor doesn’t have any parameters, nevertheless, your solution works perfectly. Many thanks!