Junior Oliveira
Junior Oliveira

Reputation: 49

Delphi - Disable [x] Close Button in VCL Styles

I'd like disable [X] close Button with VCL Style in DX Berlin.

Wy this code do not work wiht VCL Style?

EnableMenuItem(GetSystemMenu(Form3.Handle, LongBool(False)),SC_CLOSE, MF_BYCOMMAND or MF_GRAYED);

Upvotes: 5

Views: 6217

Answers (2)

SilverWarior
SilverWarior

Reputation: 8386

When using VCL Styles by default style affect the appearance of fonts being used, client area of your form and also your forms border (this also include minimize, maximize and close buttons).

So from what I see you have two options:

  1. You could change StyleElements property of your form to [seFont, seClient] which means that style will only be applied to used fonts and client area of your form but the border area of your form would be unstyled and rendered by OS.
  2. You modify the style at runtime in order to achieve desired effect. Unfortunately I don't have enough experience with Styles to present you with an example of how to achieve this.

Upvotes: 1

Alberto Miola
Alberto Miola

Reputation: 4751

If you set the action in the FormClose event to caNone, when you try to close the form (clicking on the red cross) nothing is going to happen. In this way you can disable the button.

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 //You cannot type only caNone, otherwise you'll get a compiler error
 Action := TCloseAction.caNone;
end;

You can find caNone in System.UITypes; read the documentation for more information.

Upvotes: 5

Related Questions