显示表单的参数太多,但在另一个项目中有效 - 几乎相同的代码

Too many arguments to show a form, but works in another project - Almost same code

我正在尝试开始使用我的第一个 Autodesk Inventor 插件,当然,我是从现有示例开始的,以使像我这样的新手更容易完成这项任务。

我对 VB.NET 的掌握还不错,但我不明白这里发生了什么。

在此link中:https://drive.google.com/drive/folders/1rs2zVzf8Ib8iwd8JjCWZ-KQbWJUAqFyJ?usp=sharing

有两个ZIP文件VS2019解决方法:

两者都有这行代码:

dc.Show(New WindowWrapper(ThisApplication.MainFrameHWND))

但它只在项目 This_Sample_Works.zip 中编译 - 在 This_Sample_Does_Not.zip 的项目中,我得到下图中的错误。

坦率地说,我什至没有请人帮我修好它。我只是想了解为什么它在一个项目中有效而在另一个项目中无效,尽管代码几乎相同。

困扰我的是 information/skills 我目前不必理解编译器告诉我的内容。

Public Function CreateChildDialog() As Long

    CreateChildDialog = Nothing

    Try
        'Dim dc As Object
        If Not dc Is Nothing Then
            dc.Dispose()
            dc = Nothing
        End If
        dc = New dockable_form(ThisApplication)
        dc.Show(New WindowWrapper(ThisApplication.MainFrameHWND))
        MsgBox("Handle ID:" & dc.Handle.ToInt64(), MsgBoxStyle.OkCancel, "Debug Info")
        Return dc.Handle.ToInt64()

    Catch ex As Exception
        MsgBox("There is problem in CreateChildDialog" & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.StackTrace & vbCrLf & vbCrLf & ex.ToString)
    End Try

End Function

欢迎任何帮助 - 提前致谢!

在您的项目 This_Sample_Does_Not 中,class dockable_form 是一个 Control(class 继承自 System.Windows.Forms.UserControl).

在参考项目This_Sample_Works中classform_dockable是一个Form(class继承自System.Windows.Forms.Form).

两者是非常不同的类型,尽管 Form 可以表现得像 Control,但反之则不然。控件将需要一个包含窗体。

因此,Control 没有可以在方法 Show 调用时分配的 Parent,它已经有一个 parent。

来自 MSDN - Control.Show Method

Showing the control is equivalent to setting the Visible property to true. After the Show method is called, the Visible property returns a value of true until the Hide method is called.

关于您最终首选解决方案的问题:

  • 您真的要创建一个放置在另一个窗体上的控件吗?或者
  • 您想要一个可以根据需要显示或弹出的表单吗?