来自其他形式循环的进度条值?
我想为我的应用程序创建一个进度条,我正在运行,我得到一个主窗体,它打开一个带有数据网格的子窗体,循环 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是使用不同的线程来执行冗长的操作,同时更新进度条。这不会冻结您的 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