原文: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);
时间: 2024-09-30 07:16:06