C# 有关程序调用 现有2个程序 A和B,程序B必须通过程序A去调用才能运行,而程序B不能直接双击去单独运行~~~~~这样子的话,程序B里面应该怎样写代码,才能做到这个效果啊????各位高手!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果A,B两个程序都是你自己写的话可以用参数啊。B程序Program.cs写成这样:static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length <= 0) { Application.Exit(); } if (args.Length == 1) { if (args[0] == "B") { Application.Run(new Form1()); } else { Application.Exit(); } } } }A的form中放一个输入框输入参数(当然你可以用配置文件),放一个按钮启动Bpublic partial class Form1 : Form { public Form1() { InitializeComponent(); } public bool StartProcess(string filename, string[] args) { try { string s = ""; foreach (string arg in args) { s = s + arg + " "; } s = s.Trim(); Process myprocess = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(filename, s); myprocess.StartInfo = startInfo; myprocess.StartInfo.UseShellExecute = false; myprocess.Start(); return true; } catch (Exception ex) { MessageBox.Show("启动应用程序时出错!原因:" + ex.Message); } return false; } private void button1_Click(object sender, EventArgs e) { string[] arg = new string[1]; arg[0] = textBox1.Text.Trim(); StartProcess(@"F:\test\B\B\bin\Debug\B.exe", arg); } } Console.Write格式化输出字符串,请问我错在哪 关于propertyGrid控件的使用 实时查检SQL表中是否有新记录是用计时器来完成还是用别的什么好? 高手帮帮忙! 可以把SQL的存储过程放在程序代码中吗? c#语法里有科学计数法吗~ 请教一个简单的数据更新问题? 请问怎样将运行的程序自动最小化到任务栏中? WINXP是否全面支持VISUAL STUDIO 7?还是要等下一个WINXP++? 如何让RDLC报表中图表x轴类别全部显示 小菜菜问问题 datagridview中的数据写入到EXCEL中格式的问题
B程序Program.cs写成这样:
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length <= 0)
{
Application.Exit();
}
if (args.Length == 1)
{
if (args[0] == "B")
{
Application.Run(new Form1());
}
else
{
Application.Exit();
}
}
}
}A的form中放一个输入框输入参数(当然你可以用配置文件),放一个按钮启动B
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public bool StartProcess(string filename, string[] args)
{
try
{
string s = "";
foreach (string arg in args)
{
s = s + arg + " ";
}
s = s.Trim();
Process myprocess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(filename, s);
myprocess.StartInfo = startInfo;
myprocess.StartInfo.UseShellExecute = false;
myprocess.Start();
return true;
}
catch (Exception ex)
{
MessageBox.Show("启动应用程序时出错!原因:" + ex.Message);
}
return false;
}
private void button1_Click(object sender, EventArgs e)
{
string[] arg = new string[1];
arg[0] = textBox1.Text.Trim();
StartProcess(@"F:\test\B\B\bin\Debug\B.exe", arg);
}
}