关于打开新窗体的
关于打开新窗体的求助
我创建了一个窗体,名称是Home,然后生成后,打开应用程序可以正常运行,然后需要的效果是在第二次在点击应用程序后不是在新建一个窗体,而且判断进程是否已经有已经运行了的应用程序,如果有则前置。
public static bool AppRunAlready(string appName)
{
Process[] app = Process.GetProcessesByName(appName);
return app.Length > 1;
}
private void Form1_Load(object sender, EventArgs e)
{
//判断进程
if (Home.AppRunAlready("Szhyjr"))
{
//MessageBox.Show("调度查询系统已经启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
求助这里需要怎么写。。。。。
}
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.TopMost = false;
}
public void OpenHome()
{
this.TopMost = true;
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.TopMost = false;
}
------解决方案--------------------
自己补上API定义
h = FindWindow(主程序标题, null);
SetForeGroundWindow(h);
Application.Exit();
------解决方案--------------------
yearTermForm 是定义好的全局变量。
------解决方案--------------------
[DllImport("user32.dll",EntryPoint="Findwindow")]
public static extern int FindWindow (string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
这就是那两个需要导入的API
------解决方案--------------------
在program.cs里操作如下:
添加命名空间:
using System.Diagnostics;
using System.Threading;
然后在主函数里:
main()
{
bool instantiated;
Mutex mutex = new Mutex(true,"f6ForSingle", out instantiated);
if (!instantiated)
{
MessageBox.Show("你已经启动程序了。别闹了,好吗?");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
GC.KeepAlive(mutex);
}
我创建了一个窗体,名称是Home,然后生成后,打开应用程序可以正常运行,然后需要的效果是在第二次在点击应用程序后不是在新建一个窗体,而且判断进程是否已经有已经运行了的应用程序,如果有则前置。
public static bool AppRunAlready(string appName)
{
Process[] app = Process.GetProcessesByName(appName);
return app.Length > 1;
}
private void Form1_Load(object sender, EventArgs e)
{
//判断进程
if (Home.AppRunAlready("Szhyjr"))
{
//MessageBox.Show("调度查询系统已经启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
求助这里需要怎么写。。。。。
}
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.TopMost = false;
}
public void OpenHome()
{
this.TopMost = true;
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.TopMost = false;
}
------解决方案--------------------
自己补上API定义
h = FindWindow(主程序标题, null);
SetForeGroundWindow(h);
Application.Exit();
------解决方案--------------------
if (yearTermForm == null
------解决方案--------------------
yearTermForm.IsDisposed)
{
yearTermForm = new YearTermForm();
yearTermForm.MdiParent = this;
yearTermForm.WindowState = FormWindowState.Maximized;
yearTermForm.Show();
}
else
yearTermForm.Activate();
yearTermForm 是定义好的全局变量。
------解决方案--------------------
[DllImport("user32.dll",EntryPoint="Findwindow")]
public static extern int FindWindow (string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
这就是那两个需要导入的API
------解决方案--------------------
在program.cs里操作如下:
添加命名空间:
using System.Diagnostics;
using System.Threading;
然后在主函数里:
main()
{
bool instantiated;
Mutex mutex = new Mutex(true,"f6ForSingle", out instantiated);
if (!instantiated)
{
MessageBox.Show("你已经启动程序了。别闹了,好吗?");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
GC.KeepAlive(mutex);
}