进度条与msgbox

时间:2015-02-27 03:39:40

标签: vb.net visual-studio-2012

我正在使用具有进度条的登录表单,正确登录后,进度条将显示进度并显示MsgBox。我有一个问题,MsgBox没有显示。

Public Class Form1

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
    ProgressBar1.PerformStep()
    If ProgressBar1.Value >= ProgressBar1.Maximum Then
        Timer1.Stop()
        ProgressBar1.Value = ProgressBar1.Minimum
        Label3.Text = "Completed"
    End If
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text = "a" And TextBox2.Text = "a" Then
        ProgressBar1.Maximum = 100
        ProgressBar1.Step = 2
        ProgressBar1.Value = ProgressBar1.Minimum
        Label3.Text = "Processing..."
        If CheckBox1.Checked Then
            Timer1.Start()
            If Label3.Text = "Completed" Then
                MsgBox("Logged in as Admin", MsgBoxStyle.Critical, "Welcome!")
                Me.Hide()
                Form2.Show()
            Else
            End If

        Else
            ProgressBar1.Maximum = 100
            ProgressBar1.Step = 2
            ProgressBar1.Value = ProgressBar1.Minimum
            Label3.Text = "Processing..."
            Timer1.Start()
            If CheckBox1.Checked Then
            Timer1.Start()
            If Label3.Text = "Completed" Then
                MsgBox("Logged in as Admin", MsgBoxStyle.Critical, "Welcome!")
                Me.Hide()
                Form2.Show()
            Else
            End If
        End If
    Else
        MsgBox("Username and Password Incorrect!", MsgBoxStyle.Critical, "Error")
    End If
  End Sub
End Class

1 个答案:

答案 0 :(得分:0)

尝试在计时器的Tick事件中显示messageBox,而不是在Button的Click事件中显示。代码应该是

Public Class Form1

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
    ProgressBar1.PerformStep()
    If ProgressBar1.Value >= ProgressBar1.Maximum Then
        Timer1.Stop()
        ProgressBar1.Value = ProgressBar1.Minimum
        Label3.Text = "Completed"
        MsgBox("Logged in as Admin", MsgBoxStyle.Critical, "Welcome!")
        Me.Hide()
        Form2.Show()
    End If
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text = "a" And TextBox2.Text = "a" Then
        ProgressBar1.Maximum = 100
        ProgressBar1.Step = 2
        ProgressBar1.Value = ProgressBar1.Minimum
        Label3.Text = "Processing..."
        If CheckBox1.Checked Then
            Timer1.Start()

        Else
            ProgressBar1.Maximum = 100
            ProgressBar1.Step = 2
            ProgressBar1.Value = ProgressBar1.Minimum
            Label3.Text = "Processing..."
            Timer1.Start()
            If CheckBox1.Checked Then
            Timer1.Start()
        End If
    Else
        MsgBox("Username and Password Incorrect!", MsgBoxStyle.Critical, "Error")
    End If
  End Sub
End Class

希望它可以帮到你。