Adding a regular Windows Form to a DockableWindow

Adding a regular Windows Form to a DockableWindow

Anders_Olsen
Contributor Contributor
548 Views
2 Replies
Message 1 of 3

Adding a regular Windows Form to a DockableWindow

Anders_Olsen
Contributor
Contributor

I'm trying to create a custom dockable window in my Inventor Addin (VB.NET), which will take a Windows Form - which I will populate with desired content - as its content.

 

I have a placeholder form ready, and I actually managed to get the dockable window to show up, but either with nothing in it, or with an empty form window, with none of the buttons and text boxes I added for verifiication, showing up. Right now, the dockable window itself is not even getting loaded, and I'm not sure what's different from when earlier "partial successes".

 

Either way - the API help tells me to make sure to "create the dialog as a modeless dialog", and I'm not sure how exactly to do that. I know I need to call "<dialog>.show()" for modeless interaction, but do I put that as a "Me.Show" inside the form code as an event handler On Load, or do I call it directly within the "Activate"-Sub? Or do I handle modeless interaction in some completely different way?

 

This is my code, inside the "Activate"-sub of the StandardAddinServer-class.

Dim UiRessourceDocker As DockableWindows = g_inventorApplication.UserInterfaceManager.DockableWindows
Dim cheatSheetWindow As DockableWindow = UiRessourceDocker.Add(AddInClientID, "CheatSheet", "Cheat Sheet")
cheatSheetWindow.Visible = True

Dim oCheatSheet As New Form1
cheatSheetWindow.AddChild(oCheatSheet.Handle)

 

This is my form, and the code behind it:

 

2024-06-01 00_03_32-Window.png

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("Test")
    End Sub
End Class

 

0 Likes
Accepted solutions (1)
549 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

At first you need to declare variable for form (oCheatSheet) at the AddIn level outside the Activate method. The same I recommend you for cheatSheetWindow variable.

 

Another improvement can be to use UserControl instead of Form.

For the real sample you can see my SelectionInfo addin on GitHub. Here I use just single PropertyGrid as a Control, but your own UserControl can be used.

0 Likes
Message 3 of 3

Anders_Olsen
Contributor
Contributor
Thank you, Michael - moving the declarations outside the Activate method did the trick!
0 Likes