来自其他形式循环的进度条值?

发布于 2024-08-05 21:57:35 字数 455 浏览 1 评论 0原文

我想为我的应用程序创建一个进度条,我正在运行,我得到一个主窗体,它打开一个带有数据网格的子窗体,循环 i<30。循环在查询数据库时需要一些时间。

这种停滞对用户来说就像软件被卡住了一样,所以我正在考虑创建一个进度条来显示操作在循环中持续了多长时间。

需要什么我该如何开始解决这个问题?

form1 = 主窗体 Child1 = 数据网格表单 Child2 = Progressbar form

我正在考虑让主窗体保存一个 int 变量 poX = 0 child1 在循环中执行操作,

for (int i, i < 30, i++)
{
   //code for query
   form1.posX = form1.posX++
}

然后让 Child2 使用 poX 来推动进度条。 但这是正确的道路吗?我如何将值从孩子传递到主窗体并返回?

I wold like to create a progressbar for my application, im running i got one main form that opens a Child form with a datagrid with a loop i<30. the loop takes a bit of time as it querys the database.

this hold up looks to the user like the software is stuck, so i was thinking of creating a progressbar to show how long the operation is in the loop.

what is needed how do i start solving this problem?

form1 = Main form
Child1 = datagrid form
Child2 = Progressbar form

i was thinking on letting the main form hold a int variable poX = 0
and the child1 do in the loop

for (int i, i < 30, i++)
{
   //code for query
   form1.posX = form1.posX++
}

then let Child2 use the poX to progress the bar.
But is this the correct path? and how do i pass values from the children to the main form and back?

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

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

发布评论

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

评论(1

顾冷 2024-08-12 21:57:35

您需要做的是使用不同的线程来执行冗长的操作,同时更新进度条。这不会冻结您的 UI 线程。查看 BackgroundWorker 类和 如何使用BackgroundWorker

What you need to do is use a different thread to perform your lengthy operation while updating the progress bar. This wont freeze your UI thread. Take a look into BackgroundWorker class and How To Use BackgroundWorker

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