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

113 views Asked by At

I'm trying to get started with my first add-in for Autodesk Inventor, and of course, I'm starting from an existing sample to make this task easier for a newbie like me.

I have a decent command of VB.NET, but I cannot understand what's going on here.

In this link: https://drive.google.com/drive/folders/1rs2zVzf8Ib8iwd8JjCWZ-KQbWJUAqFyJ?usp=sharing

There are two ZIP files with VS2019 Solutions:

  • This_Sample_Works.zip - I used this as the baseline for my new project
  • This_Sample_Does_Not.zip

In both, there is this line of code:

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

But it only compiles in the project This_Sample_Works.zip - In the project within This_Sample_Does_Not.zip, I get the error in the image below.

Frankly, I'm not even asking someone to fix it for me. I just wanted to understand why it works in one project and not in another, despite the code being virtually the same.

What is bugging me is what piece of information/skills I currently don't have to understand what the compiler is telling me.

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

Working Sample

Does not work here

Any help is welcome - Thanks in advance!

1

There are 1 answers

1
JayV On BEST ANSWER

In your project This_Sample_Does_Not the class dockable_form is a Control (the class inherits from System.Windows.Forms.UserControl).

In the reference project This_Sample_Works the class form_dockable is a Form (the class inherits from System.Windows.Forms.Form).

The two are very different types, though a Form can behave like a Control, the opposite is not true. A control will need a containing form.

Thus, the Control does not have a Parent that can be assigned when the method Show is called, it already has a parent.

From 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.

Questions for your final preferred solution:

  • Do you really want to create a Control that is placed on another form? or
  • Do you want a Form that can be shown or popped up as required?