I have the following folder hierarchy inside my solution folder:
Solution Name
- Program.cs
- Folder 1
- File1.cs
How can I run the File1.cs (Windows Form) inside the Program.cs?
I tried updating the syntax inside the Program.cs file:
Application.Run(Solution_Name.Folder_1.File.cs);
but it's not working.
Solution:
The syntax I was looking for is:
Application.Run(new Solution_Name.Folder_1.File1());
Have you tried
Application.Run(new File1());
I am able to run it succesfully
or you can also add
using Solution_Name.Folder_1;
I dont think there can exist more than one form with the same name irrespective of it's location
The problem looks with correct path.
1- First check the namespace where form is located. open the File1.cs and see what name space it is in. 2- Use the full path to form Application.Run(new Solution_Name.Folder_1.File());
The syntax looks correct but there may be issue with namespace where you are looking for in question form.
Try this:
//Suppose your File1 form class has the same name with the File1.cs containing it.
Application.Run(new Folder_1.File1());
Or even better, you should add some using declaration
and access your File1
class directly like this:
using Folder_1;
//...
Application.Run(new File1());
NOTE : each folder in the project will be treated as a namespace
.
Application.Run(new projectName.folderName.Form1());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.