本文介绍了如何在vb.net中调用进度条形成另一个窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在一个表单中使用进度条,如果我从另一个表单调用进度条,需要显示带动画的进度条,如计时器启动和显示进度正在进行中bar。如何启动计时器并以另一种形式显示进度条。



EgI有form1和form2,在form1我有一个按钮,在form2我有进度条计时器启动和进度代码如下



Hi
I am use progress bar in one form,if i call progress bar form another form,need to show progress bar with animation,like timer start and show progressing in progress bar.How to start timer and show progress bar in another form.

E.g.I have form1 and form2,in form1 i have one button,in form2 i have progress bar with timer start and progressing code like below

Public Class ProgressBar
    Private ticks As Integer = 0
    Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick
        ticks += 1
        ProgressBar1.Value1 = ticks
        If ticks = 100 Then
             ticks = 0
        End If
    End Sub

    Private Sub ProgressBar_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Timer1.Enabled = False
    End Sub

    Private Sub ProgressBar_Load(sender As Object, e As EventArgs) Handles Me.Load
        Timer1.Enabled = True
    End Sub
End Class





在上面的代码中我将开始进度,一旦计时器滴答达到100老化我重启进度,这里一旦form2开始,我开始进度动画和一次form2,关闭我停止进度条动画。我直接启动form2页面它工作正常,但如果我从form1按钮单击事件调用form2它将不会显示进度条动画,只是它出现没有进度动画。



下面是form1按钮点击活动。





In above code i will start progress,once timer ticks reach 100 aging i restart progress,here once form2 start ,i start progress animation and once form2, close i stop progress bar animation.Here i start form2 page directly it work fine,but if i call form2 from form1 button click event it will not show progress bar animation,simply it appear without progress animation.

Below is form1 button click event.

Dim proBar As New ProgressBar
proBar.Show()





为什么如果打开form2直接它可以工作,如果调用另一个页面它不起作用?



注意:在form1按钮点击事件我有一些其他的过程,即我将在树视图中加载很多节点(超过10000个节点),它需要更多的时间并且它挂了几分钟,所以这里我需要调用进度条,所以一旦开始加载树视图中的节点我需要调用进度条,一旦完成需要关闭进度条。



请尽快回复



问候

Aravind



Why if open form2 directly it work,if call form another page it not work ?

Note:In form1 button click event i have some other process,i.e i will load lot of nodes(more than 10000 nodes) in treeview,it take more time and it hang few mins,so here i need to call progress bar,so once start load nodes in treeview i need to call progress bar and once finish need to close progress bar.

Pls reply asap

Regards
Aravind

推荐答案

'Declare the event as so...
Public Event ProgressChanged As ProgressChangedEventHandler



然后看看谷歌,或者多线程示例。


Then look at Google to Raise An Event from another form, or this SO Question for a multithreaded example.

' This event handler updates the progress bar accordingly.
Private Sub backgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles backgroundWorker1.ProgressChanged
    Me.progressBar1.Value = e.ProgressPercentage
End Sub



该示例使用后台工作程序。


The example makes use of a background worker.



这篇关于如何在vb.net中调用进度条形成另一个窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:46