Adding the property and make CreateParams
behave accordingly is not the problem I suppose. Taking the new setting in effect immediately probably is.
Call RecreateWnd
when the property is toggled. This will lead to dropping the current Windows handle, and recreating it, including making use of your overriden CreateParams
routine.
All in all:
type
TMyButton = class(TButtonControl)
private
FOwnerDraw: Boolean;
procedure SetOwnerDraw(Value: Boolean);
protected
procedure CreateParams(var Params: TCreateParams); override;
published
property OwnerDraw: Boolean read FOwnerDraw write SetOwnerDraw
default False;
end;
procedure TMyButton.CreateParams(var Params: TCreateParams);
const
OwnerDraws: array[Boolean] of DWORD = (0, BS_OWNERDRAW);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or OwnerDraws[FOwnerDraw];
end;
procedure TMyButton.SetOwnerDraw(Value: Boolean);
begin
if FOwnerDraw <> Value then
begin
FOwnerDraw := Value;
RecreateWnd;
end;
end;