我有一个 winForm,它在加载时运行模块中的一些代码。我希望我的表单在代码运行时保持在顶部,表单包含一个进度条,因此用户必须看到进度。
我已将我的表格设置TopMost=True
为ShowDialog
我遇到的问题是,当程序执行它们的工作时,表单是不可见的。在我以前的 VBA 日子里,我曾经Repaint
解决过这个问题,但我在 VB.net 上没有这样的选项。我已经做了一些研究,并且我看到了很多地方都在使用Invalidate
,但那里也没有。
如何防止我的表单消失并确保它在代码运行时保持在顶部。
Private Sub frmDataImportSplash_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim intProgressWidth As Integer = 214
Dim intProgress As Integer = 0
'Before procedures perform the following checks:
'Check to see if Cancel has been clicked
'Set the lblProgressBar width to 0
'Change the lblPctCompleted caption to 0% Completed
'Change the lblStatus Caption to Importing Files
'Display the lblStats
checkCancel(Cancel:=False)
Me.prgStatus.Width = 0
Me.lblPctCompleted.Text = "0% Completed"
Me.lblStatus.Text = "Preparing Imports"
Me.lblStatus.Visible = True
checkCancel(Cancel:=False)
Me.Invalidate()
Me.prgStatus.Width = 20
intProgress = (Me.prgStatus.Width / intProgressWidth) * 100
Me.lblPctCompleted.Text = intProgress & "% Completed"
Me.Invalidate()
'Here is where my form dissapears
formatModule.importSheets()
checkCancel(Cancel:=False)
Me.Invalidate()
Me.prgStatus.Width = 60
intProgress = (Me.prgStatus.Width / intProgressWidth) * 100
Me.lblPctCompleted.Text = intProgress & "% Completed"
Me.Invalidate()
formatModule.prepareExports()
End Sub
End Class