程序的右上角不是有三个小按钮吗,一个最小化,一个最大化,一个关闭,我想在点击关闭后,程序给出提示,如果选择yes就退出,如果选择no就不退出,请问这段程序应该怎么写啊?

解决方案 »

  1.   

    在form的onclose事件中写if Application.MessageBox('确实要退出吗?','警告',MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON3)<>IDyes then
    exit
    else
    close
    ;
      

  2.   

    兄弟,你这样的话,点击yes会一直出现提示,点击no反而推出了,这样不行啊~
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      closeFlag:integer = 0;implementation{$R *.dfm}procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if closeFlag = 0 then
      begin
         application.MessageBox('非法退出','错误',MB_OK);
         canClose:=false;
      end;
      if closeFlag = 1 then
      begin
         if application.MessageBox('要退出吗?','警告',MB_YESNO) = IDYES
         then
           canClose:=true
         else
           canClose:=false;
      end;     
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      closeFlag:=1;
      self.Close;
    end;end.在D7中测试通过,其中的关闭条件(即何时将closeFlag设为1)你可以根据自己的需要来进一步设置.