Opening & Closing forms correctly

You can post your problem related to Microsoft Visual Studio Projects here. We will try our best to help you out.
Post Reply
Johnson
Posts: 18
Joined: Sat Feb 18, 2017 9:10 am

Opening & Closing forms correctly

Post by Johnson » Tue Mar 07, 2017 8:57 am

What would be the correct method to create an instance of a form? Currently, I add this to my AddinGlobal class in my Class project-

Code: Select all

Public Shared fForm As Form
Then, when I need the form to be shown, I use this in the ribbon button command (loaded into Inventor)

Code: Select all

AddinGlobal.fForm = New fMain
AddinGlobal.fForm.Show()
This creates a new instance of the form. I have done it this way so that fForm can be accessed by other functions.

In my Form Class, I have these members that are new instances of some UserControls I have created

Code: Select all

Public Shared pgStructure As New pAssyStructure
    Private pgAssembly As New pAssembly
    Private pgBorders As New pAssembly
    Private pgFlatPatt As New pFlatPattern
    Private pgPart As New pPart
    Private pgPresentation As New pPresentation
    Private pgSetting As New pSettings
    Private pgFrontSheet As New pFront
Problem:

When I load the form first time, it works fine and everything loads as it should. When I close the form and then open it again, I get an errorImage
So, what is the best method to load the form, allow it to be accessible and open every time?

Thanks

Post Reply