如何重新绘制winForm

时间:2013-10-05 23:16:52

标签: vb.net

我有一个winForm,在加载它运行一些模块的代码。我希望我的表单在代码运行时保持在顶部,表单包含一个进度条,因此用户必须看到进度。

我已将表单设置为TopMost=TrueShowDialog

我遇到的问题是,当程序执行其工作时,表单不可见。在我过去的旧版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

1 个答案:

答案 0 :(得分:1)

您在Form_Load事件中执行此操作 - 在显示表单之前发生。您可以将此代码移动到form_shown事件。然后代码将在向用户显示表单后运行。