将页面发送到打印机时显示进度条 (WPF)

发布于 2024-09-19 03:31:54 字数 107 浏览 10 评论 0原文

我正在使用流程文档在 WPF 中创建打印输出。这些打印输出设置在放置 DocumentViewer 的单独窗口中。 当用户单击打印时,我想显示一个进度条,通知正在发送到打印机的当前页面。我该怎么做?

I am creating printouts in WPF using flow documents. These printouts are set in separate window where DocumentViewer is placed.
When user clicks print I would like to show a progress bar that informs about current page that is sending to the printer. How can I do this?

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

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

发布评论

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

评论(1

流云如水 2024-09-26 03:31:54

我不确定你的打印代码到底在哪里,或者你想要进度条在哪里,但我最近做了类似的事情。这将在 VB.net 中进行。

首先,在与用于将页面发送到打印机的代码相同的类中创建一个新的进度条。然后,我们将利用代码块中的“自上而下”顺序来更改进度条。

默认情况下,进度条的值应设置为“0”。现在,在将页面发送到打印机的代码中,您将增加进度条的值(例如使用代码“MyProgressBar.Value = MyProgressBar.Value + 1”)。将此代码放在要显示进度的每一行代码之间。

但是,我会将代码的“+ 1”部分更改为另一个值,以便进度条在每个步骤后均等地进行。如果你有三行代码,则使用“+ 33”(100\3),四行使用“+ 25”等。

最后,在代码末尾,设置“MyProgressBar.Value = 100”

这只有效但是,如果您可以访问超过一行的代码。对于一行代码,我不确定它是如何工作的,除非您可以到达该行指向的代码块。

如果您必须使用另一个类的代码,您可能需要执行类似的操作...

Dim MyWindowWhereProgressIs As New MyWindowWhereProgressIs

然后,每次需要更改值时,尝试...

MyWindowWhereProgressIs.MyProgressBar.Value = MyWindowWhereProgressIs.MyProgressBar.Value + 1

我不完全确定最后两行是否代码可以工作,因为我现在离开 Visual Studio,但值得一试。

I'm not sure exactly where your print code is, or where you want the progress bar, but I did something similar to this recently. This will be in VB.net.

First of all, create a new progressbar in the same class as the code you use to send the page to the printer. Then, we're going to take advantage of the "top-down" order in a block of code to change the progress bar.

The progress bar's value should be set to "0" be default. Now, in the code for sending the page to the printer, you're going to increase the progressbar's value (such as with the code "MyProgressBar.Value = MyProgressBar.Value + 1"). Put this code in between each line of the code you want to show progress for.

I would change the "+ 1" part of the code, however, to another value, so your progress bar progresses equally after each step. If you have three lines of code, then use "+ 33" (100\3), four lines use "+ 25", etc.

Finally, at the end of the code, set "MyProgressBar.Value = 100"

This only works, however, if you have access to a code longer than one line. For one line of code, I'm not sure how this works, unless you can get to the block of code that line points to.

If you have to use code from another class, you may need to do something like...

Dim MyWindowWhereProgressIs As New MyWindowWhereProgressIs

And then, each time you need to change the value, try...

MyWindowWhereProgressIs.MyProgressBar.Value = MyWindowWhereProgressIs.MyProgressBar.Value + 1

I'm not entirely sure whether or not those last two lines of code will work, as I'm away from Visual Studio right now, but it is worth a shot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文