打印对话框焦点问题

发布于 2024-10-06 12:20:57 字数 415 浏览 0 评论 0原文

我在桌面应用程序中使用 PrintDialog。当从按钮或上下文菜单调用它时,它工作正常。但是,当我单击用于调用 PrintDialog 的工具提示按钮时,尽管 printdialog 窗口处于活动状态,但我没有将焦点放在打印按钮上。我需要点击两次才能打印。

我得到的解决方案是使用 BeginInvoke 和委托来调用异步,现在我可以通过以下代码获得焦点。

ShowThePrintDialog printD = new ShowThePrintDialog(p.ShowDialog); this.BeginInvoke(printD);

我想捕获 DialogResult 并根据在 printdialog 上单击的按钮进一步继续。

有人可以告诉我如何在使用 BeginInvoke 时捕获 DialogResult 吗?

拉曼

I am using PrintDialog in my desktop application. When it is invoked from Button or from context menu it works fine. But when I click the tooltip button for invoking the PrintDialog, despite the printdialog window is active, I am not getting the focus on the print button. I need to click twice to get the print.

The solution I got is to use BeginInvoke with delegate to call async and now I am able to get the focus with the following code.

ShowThePrintDialog printD = new ShowThePrintDialog(p.ShowDialog);
this.BeginInvoke(printD);

I want to capture the DialogResult and proceed further based on the button clicked on printdialog.

Can anybody give me an idea how to capture the DialogResult while using BeginInvoke?

Raman

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜宝宝 2024-10-13 12:20:57

PrintDialog 没有获得焦点,因为toolstripbuttons Click 事件未完成。
这可以通过使用定时器来解决:

private void toolStripButtonPrint1_Click(object sender, EventArgs e)
{
    timerPrint1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    timerPrint1.Stop();
    if (printDialog1.ShowDialog() == DialogResult.OK)
    {
        // do your stuf
    }
}

The PrintDialog doesn't get the focus, because the toolstripbuttons Click-event doesn't finish.
This can be solved by using a timer:

private void toolStripButtonPrint1_Click(object sender, EventArgs e)
{
    timerPrint1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    timerPrint1.Stop();
    if (printDialog1.ShowDialog() == DialogResult.OK)
    {
        // do your stuf
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文