我在窗体oncloses事件中,写了确认的对话框,点ok就退出,但是如果点cancel窗体还是会消失,请问怎么编写点cancel的代码啊?我用exit也不行。

解决方案 »

  1.   

    在close事件中:
    if application.messagebox('你要退出吗?','Information',mb_okcancel+mb_iconinformation)<>idok then Abort;
      

  2.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
        if application.messagebox('你要退出吗?','提示',mb_okcancel+mb_iconinformation)<>idok   then
        CanClose:=false;
    end;
      

  3.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
    CanClose:=application.messagebox('你要退出吗?','提示',MB_YESNO+MB_iconinformation)=IDYES;
    end;