简体   繁体   中英

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

Basically, im making a form that opens a form from another folder, I'm wondering how to do it since I'm making an OS that you can install apps by locating the name .csproj/form1.cs and it will use that form for whatever the form contains

here is the code I'm using to find the file/form but I dont know how to open the form

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
                }
                
            }
        }

any help will be appreciated.

if you know .exe folderis very simple.

// 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 is a VS file of your solution...

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.

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