只启动一个exe方法:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms; namespace StringToImage
{
static class Program
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String classname, String title);
[DllImport("user32.dll")]
public static extern void SetForegroundWindow(IntPtr hwnd); [STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); string p = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName(p);
if (processes.Length < )
Application.Run(new Form1());
else
{
//MessageBox.Show("程序已经运行!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
IntPtr ptr = FindWindow(null, "文字转换成图片");//"文字转换成图片"为对应窗体的Text值
if (ptr.ToString() != "")//不等于0表示找到了窗体
SetForegroundWindow(ptr); Application.Exit();
}
}
}
}