Printdialog自动取消(超时) [英] Printdialog auto cancel (timeout)
本文介绍了Printdialog自动取消(超时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
如果DialogResult没有返回60秒,我想让printdialog自动取消。
我尝试了什么:
我用这段代码开始吧。我想我需要一种方法来引入计时器来取消pdi,但我输了。
Hi
I want to have a printdialog auto cancel itself if the DialogResult isn't returned for say 60 seconds.
What I have tried:
I use this bit of code to kick it off. I guess I need a way to introduce a timer to cancel the pdi but I'm lost.
using (PrintDialog pdi = new PrintDialog())
{
if (pdi.ShowDialog(this) == DialogResult.Cancel)
{
return;
}
printPages();
}
推荐答案
private void button1_Click( object sender, EventArgs e ) {
Timer timer = new Timer() {
Interval = 10000
};
timer.Tick += Timer_Tick;
timer.Start();
try {
using ( PrintDialog pdi = new PrintDialog() ) {
if ( pdi.ShowDialog( this ) == DialogResult.Cancel ) {
return;
}
MessageBox.Show( "Printing" );
}
} finally {
timer.Stop();
timer.Dispose();
}
}
private void Timer_Tick( object sender, EventArgs e ) {
SendKeys.Send( "{ESC}" );
}
这篇关于Printdialog自动取消(超时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文