zoukankan      html  css  js  c++  java
  • WPF 进程间传递参数

    WPF 进程间传递参数    
         在软件开发中有时需要在一个软件中启动另一个软件,这时用Process.Start(“软件路径”)可以启动另一个软件。如果在这个过程中还需要传递一些参数给新启动的软件,可以通过WPF中的Application_Startup来完成:
         首先,在需要启动的WPF项目中的APP中注册Application_Startup事件:
    private void Application_Startup(object sender, StartupEventArgs e)
            {
                if (e.Args.Length == 1)
                {
                       String s = e.Args[0];                
                }
            }
         这样字符串s就可以得到主程序传过来的参数,可以把这个参数放在Properties中供MainPage调用:
         
         修改App中代码为:
    private void Application_Startup(object sender, StartupEventArgs e)
            {
                if (e.Args.Length == 1)
                {
                    this.Properties["Test"] = e.Args[0];               
                }
            }
    在MainPage中:
         txt.Text = Application.Current.Properties["Test"].ToString();
     
    那么主程序如何在启动附程序时传递参数呢?
     private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                string path = Directory.GetCurrentDirectory() + @"WpfApplication1.exe";
                if (string.IsNullOrEmpty(path) || !File.Exists(path)) return;
                Process.Start(path,"测试字符串");
            }
  • 相关阅读:
    rabbimq连接问题处理
    svn小设置
    日志的乱码,以及数据库编码问题
    Intellij Idea 14 使用jetty-maven-plugin配置运行web工程
    心血来潮
    maven nexus 私服的搭建学习
    致成长——毕业一周年
    2015-7-2
    我的JQuery复习笔记之①——text(),html(),val()的区别
    【转】title与alt的区别
  • 原文地址:https://www.cnblogs.com/infly123/p/3781239.html
Copyright © 2011-2022 走看看