我有一個winForm,它在加載時會從模塊運行一些代碼。我希望表單在代碼運行時保持最前面,表單包含一個進度條,所以用戶必須看到進度。如何重繪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
表單在處理過程中不顯示的事實清楚地表明代碼應該在運行後臺線程。看看BackgroundWorker()控件... –
@Idle_Mind這是很棒的信息。我是編程新手,所以我沒有聽說過這種控制。閱讀後,我認爲這對我想完成的任務來說是完美的。 –