主窗体有若干按钮,每个按钮可以弹出某个窗体类的一个实例,要求按按钮时如果有这个窗体类的实例就最大化这个实例,如果没有这个窗体类的实例则新建一个实例并最大化

解决方案 »

  1.   

    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写的。一看就懂~
      

  2.   

    回复人: maxxxz(ma) ( ) 信誉:100  2005-06-20 12:58:00  得分: 0  
     
     
       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()方法?
      

  3.   

    (1)
    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)