Created
October 17, 2018 12:05
-
-
Save diaolizhi/e9de5f18306a96b72d29572a4a016220 to your computer and use it in GitHub Desktop.
c# 单例窗口及其关闭处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void Dispose(bool disposing) | |
{ | |
Hide(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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