Vb.net Visual Studio 2012-进度条
我试图让我的进度条一直保持到100%,但它会更新到85-95%左右,然后打开我的下一个表单。有人能告诉我我做错了什么吗?我试图编辑步骤和睡眠计数,但我只能设法使其接近进度条的末尾。是否有代码干扰进度条Vb.net Visual Studio 2012-进度条,vb.net,visual-studio-2012,progress,Vb.net,Visual Studio 2012,Progress,我试图让我的进度条一直保持到100%,但它会更新到85-95%左右,然后打开我的下一个表单。有人能告诉我我做错了什么吗?我试图编辑步骤和睡眠计数,但我只能设法使其接近进度条的末尾。是否有代码干扰进度条 Public Class LoginForm ' 'This specifies the default value for the login attempt Dim Attempt = 0 Public Function checkinput() As Boolean ' 'T
Public Class LoginForm
'
'This specifies the default value for the login attempt
Dim Attempt = 0
Public Function checkinput() As Boolean
'
'This is the default username
Dim Uname = "Niral Mehta"
'
'This is the default password
Dim pword = "Ban4na"
'
'This assigns the value of the Username to the UserText.text variable
Dim Username = UserText.Text
'
'This assigns the value of the Password to the PassText.text variable
Dim Password = PassText.Text
'
'Here the Username and password are being assigned the values defined above, if the user input correctly matches the defined values then it returns as true
If Username = Uname And Password = pword Then
Return True
Else
'
'If the user fails to put in the correct values on the third attempt then the program automatically shuts down after warning them
If Attempt = 3 Then
MsgBox("You have failed to login correctly three times, this program will shut down as a security measure", MsgBoxStyle.OkOnly)
Me.Close()
Return False
End If
Attempt = Attempt + 1
MsgBox("Incorrect username and/or password", MsgBoxStyle.OkOnly)
Return False
End If
End Function
Private Sub KillProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KillProcess.Click
'
'When the end program button is clicked, a message box will pop up and give the options to end the program
If MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo) = DialogResult.Yes Then
Me.Close()
End If
End Sub
Private Sub PassText_TextChanged(sender As Object, e As EventArgs) Handles PassText.TextChanged
'
'This hides the password characters
PassText.PasswordChar = "#"
'This sets the character length for a password
'
PassText.MaxLength = 8
End Sub
Private Sub UserText_TextChanged(sender As Object, e As EventArgs) Handles UserText.TextChanged
'
'This sets the character length for a username
UserText.MaxLength = 14
End Sub
Private Sub StartNextForm_Click(sender As Object, e As EventArgs) Handles StartNextForm.Click
If checkinput() Then
With LoginProgress
.Visible = True
.Step = 2
.Maximum = 101
.Style = ProgressBarStyle.Blocks
.Value = 0
End With
Do
System.Threading.Thread.Sleep(100)
LoginProgress.PerformStep()
Loop Until LoginProgress.Value >= LoginProgress.Maximum
FrmMain.Show()
Me.Hide()
End If
End Sub
您的事件没有被处理,因为您正在UI线程上运行循环(占用),并且没有给UI线程消息泵任何时间来处理事件 尝试添加
Application.DoEvents()
Do
系统线程线程睡眠(100)
LoginProgress.PerformStep()
Application.DoEvents()'=LoginProgress.Maximum
使用计时器,您可以使用以下代码:
计时器代码:
Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
If prgStatus.Value = prgStatus.Maximum Then
Timer.Enabled = False
prgStatus.Value = 0
Exit Sub
End If
prgStatus.Value = prgStatus.Value + 1
If (prgStatus.Value = 1) Then
'Do something
End If
End Sub
注意:“做点什么”的所有代码必须在
prgStatus.Value = prgStatus.Value + 1
启动计时器,只需将此代码放入按钮、表单加载等
Timer.Enabled = True
你可以尽可能多
If (prgStatus.Value = 1) Then
'Do something
End If
随你的便
要延迟,只需更改progressbar的最大值或更改计时器的滴答声
希望这有帮助:)可能重复假设否决票是针对
DoEvents
,请记住我没有设计软件,也不会用这样的循环阻塞UI线程。在这种情况下,DoEvents应该可以解决UI不更新的问题,但我不打算教任何关于正确线程应用程序的课程。
If (prgStatus.Value = 1) Then
'Do something
End If