When I try to disable a Button on a styled VCL from using the follwing line of code
TButton(Sender).enabled:= False;
I get the this result (Button disabled at runtime)
instead of this!! (Button disabled at design time)
It's really confusing to have two or more Buttons with the same color beside each other, one is disabled and the other is enabled
It's clearly a bug in the VCL. The problem appears to be that modifying the
Enabled
property of a button from an event handler attached to that button does not change the visual appearance of the button. The button's behaviour is changed (you cannot click it if you setEnabled
toFalse
this way), but the visuals do not indicate it.I submitted QC#103962 and no doubt a future update will fix the problem. In the meantime I offer the following workaround:
This will force the button's window handle to be recreated and this seems to be enough to get the visuals sorted. There are probably alternative ways to work around this but this was all I have found so far.
The cause of this issue is located in the Paint method of the
TButtonStyleHook
(in the Vcl.StdCtrls unit) style hook class.Locate this code in the method
And replace for this code
Another option is rewrite the Style hook for the TButton :
Check this code based in this article Fixing a VCL Style bug in the TButton component. The advantage of ths code is which you are fixing two issues 103708 and 103962.