Private Shared instance As form1 ''singleton模式 Public Shared Function getInstance() As form1 If instance Is Nothing Then instance = New ShouZhi End If If instance.IsDisposed Then instance = New ShouZhi End If Return instance End Functionvb写的。一看就懂~
Private Shared instance As form1 ''singleton模式 Public Shared Function getInstance() As form1 If instance Is Nothing Then instance = New ShouZhi End If If instance.IsDisposed Then instance = New ShouZhi End If Return instance End Functionvb写的。一看就懂~
Public Shared Function getInstance() As form1
If instance Is Nothing Then
instance = New ShouZhi
End If
If instance.IsDisposed Then
instance = New ShouZhi
End If
Return instance
End Functionvb写的。一看就懂~
Private Shared instance As form1 ''singleton模式
Public Shared Function getInstance() As form1
If instance Is Nothing Then
instance = New ShouZhi
End If
If instance.IsDisposed Then
instance = New ShouZhi
End If
Return instance
End Functionvb写的。一看就懂~
===
在窗体的中都实现getInstance()方法?
private Form2 frm2;
private Form2 GetFrm2()
{
if(frm2 == null)
{
frm2 = new Form2();
}
if(frm2.IsDisposed)
{
frm2= new Form2();
}
return frm2;
}private void button1_Click(object sender, System.EventArgs e)
{
GetFrm().Show();
frm2.Focus();
frm2.WindowState = FormWindowState.Maximized;
}(2)
或者在Form2中:public static bool IsOpen = false;
protected override void Dispose( bool disposing )
{
IsOpen = false;
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}private void Form2_Load(object sender, System.EventArgs e)
{
IsOpen = true;
}Form1中:
private void button1_Click(object sender, System.EventArgs e)
{
if(!Form2.IsOpen)
{
frm2 = new Form2();
frm2.Show();
frm2.WindowState = FormWindowState.Maximized;
}
else
{
frm2.Focus();
frm2.WindowState = FormWindowState.Maximized;
}
}(3)
再者就用API(一时忘了哪个API)