C# Windows 窗体打印对话框单击“确定”两次有响应
我正在使用 Visual Studio 2008、.net Framework 3.5 来开发我正在开发的 Windows 窗体客户端-服务器应用程序。当我运行程序并尝试打印时出现一个奇怪的错误。打印对话框打开,但我必须单击“确定”按钮两次才能正常工作。第二次点击后,一切正常,没有错误。当我在 if (result == DialogResult.OK) 上放置断点时,断点直到第二次单击才会触发。这是代码:
private void tbPrint_Click(object sender, EventArgs e)
{
try
{
printDialog1.Document = pDoc;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
pDoc.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;
pDoc.Print();
}
...
这让我发疯,我看不到任何其他会干扰它的东西。
I'm using Visual Studio 2008, .net Framework 3.5 for a Windows forms client-server app that I'm working on. There is a weird bug when I run the program and try to print. The print dialog box opens, but I have to click the OK button twice for it to work. After the second click it works fine, no errors. When I put a breakpoint on: if (result == DialogResult.OK) , the breakpoint doesn't trigger until the second click. Here is the code:
private void tbPrint_Click(object sender, EventArgs e)
{
try
{
printDialog1.Document = pDoc;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
pDoc.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;
pDoc.Print();
}
...
This is driving me crazy, and I can't see anything else that would interfere with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 C#/WinForms 中使用
OpenFileDialog
时遇到了“第一个工具条单击无法识别”的情况。经过多次咒骂和谷歌搜索后,我这样做了:在
toolstrip1_Click
中:在使用调用
OpenFileDialog
的函数中:两行似乎是关键:
OpenFileDialog
关闭时,焦点需要重置到主窗口 (EditorForm.ActiveForm.TopLevelControl.Focus();
)this.Validate()
) 并识别鼠标事件。I came across this while having the "first toolstrip click unrecognized" using an
OpenFileDialog
in C#/WinForms. After much cursing and googling, I did this:In
toolstrip1_Click
:In the function that uses calls
OpenFileDialog
:Two things lines seem to be key:
OpenFileDialog
closes, focus needs to be reset to the main window (EditorForm.ActiveForm.TopLevelControl.Focus();
)this.Validate()
) and recognizes the mouse event.我使用计时器实现了它。
将一个计时器放到包含工具条的表单上,并将其变成一个延迟为 1 毫秒的一次性计时器。注意:计时器最初必须将“启用”设置为“假”
创建计时器滴答事件处理程序
它可能很脏,但它让我摆脱了困境。华泰
I achieved it using a timer.
Drop a timer onto the form containing the toolstrip and turn it into a one shot timer with a delay of say 1mS. Note: Timer must initially have 'Enabled' set to 'False'
Create a timer tick event handler
It may be dirty but it got me out of a hole. HTH
也许这是一个与此类似的问题: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/681a50b4-4ae3-407a-a747-87fb3eb427fd
Maybe it is an issue similar to this one: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/681a50b4-4ae3-407a-a747-87fb3eb427fd