简体   繁体   English

从文件夹访问Windows窗体

[英]Access Windows Form from a Folder

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? 如何在Program.cs中运行File1.cs(Windows窗体)?

I tried updating the syntax inside the Program.cs file: 我尝试更新Program.cs文件中的语法:

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. 1-首先检查表单所在的名称空间。 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()); 打开File1.cs并查看其所在的名称空间。2-使用完整路径形成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 declaration添加一些内容,然后像这样直接访问File1类:

using Folder_1;
//...
Application.Run(new File1());

NOTE : each folder in the project will be treated as a namespace . 注意 :项目中的每个文件夹将被视为一个namespace

Application.Run(new projectName.folderName.Form1());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM