计时器事件中进度栏的值未更新 [英] Progress Bar value not update in Timer event

查看:86
本文介绍了计时器事件中进度栏的值未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Form1上有一个进度条,在Form2上有一个按钮.当我单击该按钮时,进度条的值应在Form2上创建的Timer事件中更改.创建计时器后,我从C dll中调用了一个函数单击该按钮.您能告诉我代码有什么问题吗?代码如下

I have a progress bar on Form1 and a button on Form2 .When I click that button , the progress bar value should change in a Timer event which is created on Form2 .After creating the timer I called a function from C dll in that button click .Can u tell me what''s the wrong in code. The code is as follows

Sub THandler()
        If Net_mang_Form.Prg_bar.Value = 100 Then
            Net_mang_Form.Prg_bar.Value = 10
        Else
            Net_mang_Form.Prg_bar.PerformStep()
           
       
 End Sub





Private Sub uplod_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uplod_btn.Click


       If Net_mang_Form.dev_nm Is Nothing OrElse Net_mang_Form.dev_nm.Trim = "" Then
           Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog

           ' Descriptive text displayed above the tree view control in the dialog box
           MyFolderBrowser.Description = "Select the Folder"

           ' Sets the root folder where the browsing starts from
           'MyFolderBrowser.RootFolder = Environment.SpecialFolder.MyDocuments

           ' Do not show the button for new folder
           MyFolderBrowser.ShowNewFolderButton = False

           Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()

           If dlgResult = Windows.Forms.DialogResult.OK Then
               Net_mang_Form.snd_file_path = MyFolderBrowser.SelectedPath
               Net_mang_Form.snd_file_path = String.Concat(Net_mang_Form.snd_file_path, "\")
           Else
               MsgBox("Choose Upload File path before Continue..")
               Exit Sub
           End If

       End If

       '=================== Upload Process is going on =====================
       Net_mang_Form.disp_Label.Text = "Uploading File ..."
       Net_mang_Form.Prg_bar.Visible = True
       Net_mang_Form.Prg_bar.Value = 0
       'Net_mang_Form.prg_Timer.Interval = 30
       'Net_mang_Form.prg_Timer.Start()
       Dim t As New System.Timers.Timer
       'Dim t As New System.Windows.Forms.Timer
       AddHandler t.Elapsed, AddressOf THandler
       t.Interval = 50
       t.Start()
       'Net_mang_Form.upload_event()
       Me.uplod_btn.Enabled = False
       Windows.Forms.Application.DoEvents()

       '====================================================================

       Dim chk As Integer = file_send(dev_id, dev_type, Net_mang_Form.snd_file_path, ip_addr & "#1206", contrl_id)

       '=================== Upload Process is finished =====================
       Net_mang_Form.disp_Label.Text = "Done"
      
       t.Stop()
       Net_mang_Form.Prg_bar.Visible = False
       Me.uplod_btn.Enabled = True
       '====================================================================

       If (chk = 1) Then

           MsgBox("Upload successful")
       Else
           MsgBox("Upload Fail.Check file_transfer_log.txt file")
       End If


   End Sub

推荐答案

使用 backgroundworker 组件
在Net上搜索教程
Use backgroundworker component
Search for tutorial on Net


您好,您可以将Timer1放入form1并尝试使用.
hello, you can put Timer1 in form1 and try .


这篇关于计时器事件中进度栏的值未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆