# VBForums CodeBank > CodeBank - C# >  Opening a Form from an existing C# DLL

## smart_phil_dude1

Let's say you stored a Form in a separate DLL file created using C#, and you wanted to open up that form from your application. Here is what you can do:

Step 1: Place the DLL file in the directory of the executable when compiled (Mine would be ...Project Name\bin\Debug)
Step 2: In VC# go to "Project>Add Reference"
Step 3: In the Browse tab, locate the DLL and click OK.
Step 4: Add the following code to the top of your code:


```
using Test; //"Test" being your Dll's name
using System.IO;
```

Step 5: Now, place the following code as a function/whatever you'd like to call it. This function is what calls the form, but from my experiences, it's best to have it as a separate function and just call that function, so that you wouldn't get an error if the DLL was missing.


```
        private void OpenFromDll()
        {
            Test.Form1 TestForm1 = new Test.Form1(); //"Test" being your Dll's name, "TestForm1" being whatever form you want to open from the dll
            TestForm1.Show(); //"TestForm1" being whatever form you want to open from the dll
        }
```

Step 6: Now, you can finally call the form from the DLL, assuming that the DLL is in the same directory as the executable:


```
            if (File.Exists(Application.StartupPath + "\\Test.dll")) //"Test.dll" Being your Dll File (This is just to make sure that the DLL is in the same directory as the executable, otherwise you'd get an error.)
            {
                OpenFromDll();
            }
            else
            {
                MessageBox.Show("Missing files in the install directory, try re-installing the program.", "Missing A File!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
```

I just posted this to help any one that needs it, since I spent hours searching the internet and couldn't find anything that had this together, I had to consult multiple websites to figure out certain functions, and I also had to use my logic to figure things out, as I never took a course on programming before. This way, anyone can open a form from a DLL without any trouble :Big Grin:  

Just giving back to the community that has helped me,
Thanks,
Phil.

----------


## chemicalNova

C# Code:
using Test; //"Test" being your Dll's name
Test, in such a case, may not always be the name of the DLL. The using directive describes the namespace which your object resides in.

chem

----------


## smart_phil_dude1

Well, I guess that's true.

----------


## sharon.chapman7

Great post. this is exactly what I was looking for. I'm new to C# and this will really do what I need to do. Thanks for taking the time to post this.

Sharon :wave:

----------

