WinFrom吧?
1:使用ShowDialog()代替你使用的Show()
2:如果不能使用模式的窗口,那每次点击的时候不要重新实例化窗体,而只是在第一次点击时实例化
1:使用ShowDialog()代替你使用的Show()
2:如果不能使用模式的窗口,那每次点击的时候不要重新实例化窗体,而只是在第一次点击时实例化
解决方案 »
- 使用tcpclient向tcp端口下发数据帧问题。
- Anchor设定对那些容器起作用
- C#如何获取驱动信号强度?
- 同一页面的2个类似butto调用js 打开同一的新页,速度不同一!
- datagridview 如何灵活绑定 datatable
- WebRequest.Create 和GetResponse() 之类的函数,返回值是什么啊?如何判断是否正确啊
- 建行DLL的问题,求解
- 一个简单的问题!
- [研发人员生存状态调查问卷],答卷有分!并将回馈调查研究结果.[截至9月10日前,请相互转告]
- 把EXCEL文件导入DATAGRIDVIEW提示外部表不是预期的格式
- 新手求助!关于C#写Modbus TCP的问题 谢谢!
- 在C#中调用C++ 动态库传入回调函数指针的问题,请大家帮忙!
如果是当已经创建,第二次点击时,使其active,那就用窗口的handler作为flage,if (null == handler),创建,else
调用Win32,API,将这个handler作为其中一个参数传入,可以达到激活,并且置顶的功能。如果关闭窗口,handler设置为null
private bool checkChildFrmExist(string childFrmName)
{
foreach (Form childFrm in this.MdiChildren)
{
//用子窗体的Name进行判断,如果已经存在则将他激活
if (childFrm.Name == childFrmName)
{
if (childFrm.WindowState == FormWindowState.Minimized)
childFrm.WindowState = FormWindowState.Normal;
childFrm.Activate();
return true;
}
}
return false;
}
#endregion
用这个方法就可以了!
如果你要的不是这样,就设置一个flag好了,简单,快速。
实在不想用ShowDialog的话就设置当点击了那个弹出窗口的按钮之后把他设为不可用 Enable=false
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Demo_Project
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private Form m_SubForm;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout(); this.button1.Location = new System.Drawing.Point(111, 60);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Open";
this.button1.Click += new System.EventHandler(this.button1_Click); this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); } [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
if (m_SubForm == null)
{
m_SubForm = new Form();
m_SubForm.Closed +=new EventHandler(m_SubForm_Closed); m_SubForm.Show();
}
else
{
m_SubForm.Activate();
}
} private void m_SubForm_Closed(object sender, EventArgs e)
{
(sender as Form).Closed -= new EventHandler(m_SubForm_Closed); m_SubForm = null;
}
}
}
{
Form frmList = Application.OpenForms["Form1"]; //FOrm1为子窗体的Name
if (frmList != null)
{
frmList.Text += "\\abcde";
frimlist.Activate();
}
}试一下,不知道能否帮上忙啊
From1 Fr1 = new From1();
Fr1.ShowDialog(this);