如何使窗体右上角的的"X"按扭变成灰色?即不可用

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      EnableMenuItem(GetSystemMenu(Handle, False), SC_CLOSE, MF_GRAYED);
    end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button2: TButton;
        procedure Button2Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
    var
       SysMenu: HMENU;
     begin
       SysMenu := GetSystemMenu(Handle, False);
       EnableMenuItem(SysMenu, SC_Close,  MF_GRAYED);
     end;procedure TForm1.Button1Click(Sender: TObject);
    var
       SysMenu: HMENU;
     begin
       SysMenu := GetSystemMenu(Handle, false);
       EnableMenuItem(SysMenu, SC_Close,  MF_GRAYED);
     end;end.
      

  3.   

    变成灰色我不知道怎么做,但有另外一种方法当你点击"x"按钮时window会向你发送WM_CLOSE消息,你将这个消息截获,当接受到这个消息时执行空语句。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure CloseForm(var Message: TMessage);Message WM_CLOSE;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CloseForm(var Message: TMessage);
    begin
      //不执行任何操作
    end;end.