I have a custom button component that I have derived from TCustomButton.
To make it ownerdrawn I have overrided the CreateParams like so:
procedure TMyButton.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or BS_OWNERDRAW;
end;
end;
My button works ok with my own painting etc, but what I would like to do is provide a Boolean Property in the Object Inspector which can be used to tell my button whether it should be ownerdrawn or not.
For example, if the Property is enabled the button paints with my own paint routines as an ownerdrawn button, if the Property is toggled off then it should paint as the themed Windows button style (like a regular TButton).
CreateParams tells my button it should be ownerdawn, but I want to provide an option to tell the button whether it should be ownerdrawn or not. By changing the property at designtime or through code at runtime, I want to tell my button whether to ownerdraw or not.
Is this possible to do and if so how?
Adding the property and make
CreateParamsbehave accordingly is not the problem I suppose. Taking the new setting in effect immediately probably is.Call
RecreateWndwhen the property is toggled. This will lead to dropping the current Windows handle, and recreating it, including making use of your overridenCreateParamsroutine.All in all: