尝试显示表单后抛出InvalidOperationException

时间:2017-03-04 17:43:20

标签: vb.net

我有一个单独的表单需要显示图像然后淡出并打开主表单。当它到达Form1.Show()部分时,它会抛出InvalidOperationException。这是我的代码:

Public Class SPLASH
    Public Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal time As Integer, ByVal flags As Integer) As Boolean
    Public Enum AnimateStyles
        Slide = 262144
        Activate = 131072
        Blend = 524288
        Hide = 65536
        Center = 16
        HOR_Positive = 1
        HOR_Negative = 2
        VER_Positive = 4
        VER_Negative = 8
    End Enum
    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AnimateWindow(Me.Handle, 1000, AnimateStyles.HOR_Negative Or AnimateStyles.Blend)
        Thread.Sleep(2000)
        Form1.Show()
    End Sub
End Class

在网上找不到解决我问题的方法,我也无法自行修复。我看一下文档,但我想我可能需要等待AnimateWindow功能完全结束或者其他什么,但我不知道如何。

1 个答案:

答案 0 :(得分:-1)

找到答案!

我创建了一个函数

Private Sub Done(ByVal Sender As Object, ByVal Event As System.EventArgs)
    Dim MainForm As New Form1()
    MainForm.Show()
End Sub

之前添加了以下代码
 Dim pr As New Process
        pr.EnableRaisingEvents = True
        AddHandler pr.Exited, AddressOf Done

之后我把我常用的代码。 :)