繁体   English   中英

c# - 如何从另一个文件夹访问表单并打开它

[英]How to access a form from another folder and open it c#

基本上,我正在制作一个从另一个文件夹打开表单的表单,我想知道如何做,因为我正在制作一个操作系统,您可以通过定位名称.csproj/form1.cs 来安装应用程序,它将使用该表单无论表单包含什么

这是我用来查找文件/表单的代码,但我不知道如何打开表单

private void button9_Click(object sender, EventArgs e)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string foldername = "Win14 OS";
            string dirPath = Path.Combine(path, foldername);
            System.IO.Directory.CreateDirectory(dirPath);
            string subdir = dirPath + @"\data";
            if (Directory.Exists(subdir))
            {
                string OS_path = @"C:\Users\mervi\Desktop\Win14 OS\data";
                string file1 = OS_path + @"\Form1.cs";
                if (File.Exists(file1))
                {
                     //how to open the form? i tried 'OpeFileDialog' but it wouldn't work :(
                }
                else if (!File.Exists(file1))
                {
                   //if the file/app isn't found
                }
                
            }
        }

任何帮助将不胜感激。

如果你知道 .exe 文件夹很简单。

// Use ProcessStartInfo class
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "Test.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;

    try
    {
        // Start the process with the info we specified.
        // Call WaitForExit and then the using statement will close.
        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
    }
    catch
    {
         // Log error.
    }

.csproj 是您解决方案的 VS 文件...

暂无
暂无

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

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