怎么添加MessageBox的Cancel事件啊?(20分)

  • 主题发起人 主题发起人 忘记说爱你
  • 开始时间 开始时间

忘记说爱你

Unregistered / Unconfirmed
GUEST, unregistred user!
刚开始学delphi,从网上下载了个记事本的源代码在自己读.<br>这个是对记事本中的新建命令进行的编程.可是没有MessageBox的Cancel的响应<br>该如何添加呢 ?<br>procedure TForm1.N24Click(Sender: TObject);<br>var<br>s:integer;<br>begin<br>if richedit1.Modified then<br>s:=application.MessageBox('文件已改变是否保存','确认框',MB_YESNOCANCEL)<br> &nbsp;//if s=idCANCEL then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//到底应该怎么添加Cancel事件?<br> &nbsp;//begin<br> &nbsp;//Form1.ShowModal;<br> &nbsp;//end;<br>else<br>richedit1.Clear;<br>if s=idYES then<br>begin<br>savedialog1.Filter:='*.txt';<br>savedialog1.FileName:='*.txt' ;<br>if savedialog1.Execute then<br>begin<br>richedit1.Lines.SaveToFile(savedialog1.FileName);<br>richedit1.Clear;<br>end;<br>end<br>else<br>richedit1.Clear;<br>end;<br>procedure TForm1.N26Click(Sender: TObject);<br>var<br>i: integer;<br>begin<br>i:=0;<br>if &nbsp;printdialog1.Execute then<br>begin<br>printdialog1.Collate:=true;<br>for i:=printdialog1.FromPage to printdialog1.ToPage do<br>end;<br>end;
 
if application.MessageBox('你确定要保存吗?','提示',MB_okcancel)=IDOK then
 
我现在把程序更改为如下:<br>procedure TForm1.N24Click(Sender: TObject);<br>var<br>s:integer;<br>begin<br>if richedit1.Modified then<br>s:=application.MessageBox('文件已改变是否保存?','确认框',MB_YESNOCANCEL)<br> &nbsp;//if s=idCANCEL then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//到底应该怎么添加Cancel事件?<br> &nbsp;//begin<br> &nbsp;//Form1.ShowModal;<br> &nbsp;//end;<br>else<br>richedit1.Clear;<br>if s=idCANCEL then<br>Form1.Show;<br>if s=idYES then<br>begin<br>savedialog1.Filter:='*.txt';<br>savedialog1.FileName:='*.txt' ;<br>if savedialog1.Execute then<br>begin<br>richedit1.Lines.SaveToFile(savedialog1.FileName);<br>richedit1.Clear;<br>end;<br>end &nbsp; &nbsp; &nbsp; //; is not allowed before else<br>else<br>richedit1.Clear;<br>end;
 
case application.MessageBox('你确定要保存吗?','提示',MB_okcancel) of<br>0:...<br>1:...<br>end;
 
不论我改为这样<br>if s=idCANCEL then<br>Form1.Show;<br>或者<br>if s=idCANCEL then<br>richedit1.Show;<br>都是把richedit1里的文字清空,怎么才能不清空呢 ?<br>还有<br>if s=idCANCEL then<br>Form1.Show;<br>和<br>if s=idCANCEL then<br>begin<br>Form1.Show;<br>end;<br>应该没有区别吧 这个问题好弱弱啊
 
已经搞定了 是后面的 <br>else<br>richedit1.Clear;<br>清空的 谢谢大家啦
 
后退
顶部