Skip to content

Instantly share code, notes, and snippets.

@diaolizhi
Created October 17, 2018 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diaolizhi/e9de5f18306a96b72d29572a4a016220 to your computer and use it in GitHub Desktop.
Save diaolizhi/e9de5f18306a96b72d29572a4a016220 to your computer and use it in GitHub Desktop.
c# 单例窗口及其关闭处理
public partial class Form2 : Form
{
//唯一实例
private static Form2 obj = null;
private Form2()
{
//初始化控件(自动生成)
InitializeComponent();
}
//设置标签文字内容
public void setHelpInfo(String str)
{
helpInfo.Text = str;
}
//返回唯一实例
public static Form2 GetForm2()
{
return obj;
}
//静态方法
static Form2()
{
if(obj == null)
{
obj = new Form2();
}
}
}
protected override void Dispose(bool disposing)
{
Hide();
}
private void 查看帮助ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = Form2.GetForm2();
form2.setHelpInfo("This Help Info.");
form2.Show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment