Winform两个项目间的调用

Winform1:

static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length == 1)
            {
                Application.Run(new frmMain(args[0]));
            }
            else
            {
                Application.Run(new frmMain());
            }
        }
    }

 

Winform2:

private void btnDesigner_Click(object sender, EventArgs e)
        {
            string strPath = string.Format(@"D:\工作\标签模板设计项目\LabelDesigner\bin\Debug\");
            Process process = new Process();
            process.StartInfo.WorkingDirectory = strPath;
            process.StartInfo.FileName = "LabelDesigner.exe";
            //参数为字符串形式,多个参数用空格隔开
            string tmpFile = Path.GetTempFileName();
            using (StreamWriter sw = File.CreateText(tmpFile))
            {
                sw.WriteLine(txtLabelTemplate.Text);
            }
            process.StartInfo.Arguments = tmpFile;
            process.StartInfo.UseShellExecute = true;
            process.Start();
            process.WaitForExit();

            StreamReader sr = new StreamReader(tmpFile);
            string strContent = sr.ReadToEnd();
            sr.Close();
            txtLabelTemplate.Text = strContent;
        }

posted on 2023-08-02 16:26  *tfe*  阅读(64)  评论(0编辑  收藏  举报

导航