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:
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.Code:using Test; //"Test" being your Dll's name using System.IO;
Step 6: Now, you can finally call the form from the DLL, assuming that the DLL is in the same directory as the executable:Code: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 }
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 troubleCode: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); }![]()
Just giving back to the community that has helped me,
Thanks,
Phil.


Reply With Quote
