INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How To

How do I disable the [ X ] close button on forms? by djjd47130
Posted: 14 Sep 11

This is not necessarily how to Hide this button, nor is it how to ignore the click event of it either. Instead, this is how to actually disable the close button of a form by graying it out. Windows provides this ability, but it is not implemented in Delphi's VCL forms. Therefore, you need to do it yourself.

I added this to my form by adding a new boolean property "CloseButtonEnabled". By default of course this will be true, then set it to false as needed to disable (or gray out) the close button, and back to true to be normal again.

In the form's class...

CODE

type
  TForm1 = class(TForm)
  private
    fCloseButtonEnabled: Bool;
    procedure SetCloseButtonEnabled(const Value: Bool);
  public
    property CloseButtonEnabled: Bool read fCloseButtonEnabled write SetCloseButtonEnabled;
  end;

And in the implementation...

CODE

procedure TForm1.SetCloseButtonEnabled(const Value: Bool);
var
  hSysMenu: HMENU;
begin
  fCloseButtonEnabled := Value;
  hSysMenu:= GetSystemMenu(Self.Handle, False);
  if hSysMenu <> 0 then begin
    if Value then
      EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED)
    else
      EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED);
    DrawMenuBar(Self.Handle);
  end;
end;
 

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close