且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF 接收exe传的值

更新时间:2022-10-06 15:11:41

原文:WPF 接收exe传的值

一,首先重载APP

 protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args != null && e.Args.Count() > 0)
            {
                this.Properties["str1"] = e.Args[0];
            }
            base.OnStartup(e);
        }

 

 

二,在需要接收的窗体的loaded事件中接收值

 private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (Application.Current.Properties["str1"] != null)
            {
                this.textBox2.Text = Application.Current.Properties["str1"].ToString();
            }
        }

 

 

测试代码

System.Diagnostics.ProcessStartInfo a = new System.Diagnostics.ProcessStartInfo(@"F:\WpfApplication3.exe", "12   23");
System.Diagnostics.Process.Start(a);