比方说QQ窗体好友聊天对话框的那个,双击一个人的头像会调用聊天对话框,但是再双击同一个头像还是那个对话框,如果此时双击另一个好友的头像会弹出新一个的窗体?
怎么控制?谢谢

解决方案 »

  1.   


    支持,实现用getInstance()方法
      

  2.   

    解决你问题的算法,比较简单。1.建立一个窗体集合,
    2.为每个对话框添加一个Id属性原来区别去他类似对话框,比如QQ号码,
    3.在每次实例化对话框之前在窗体容器中判断一下是否已经存在相同QQ号的窗体,如果存在就调用该窗体的Form.Show或者Form.Active()方法。如果存在就创建一个,同时保存该创建的窗体到集合中。
    4.如果关闭窗体,在窗体关闭前,从集合中移除该窗体项。
      

  3.   

    打开窗口时,记录名称。再点击时判断窗体是否存在
    可参考myqq.
      

  4.   

    写了个demo,希望对楼主能有所帮助
    CFMain.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace OneFormDemo
    {
        public partial class Frmmain : Form
        {
            public static List<CFone> openedForm = new List<CFone>();
            public Frmmain()
            {
                InitializeComponent();
            }        private bool findForm(CFone fr)
            {
                foreach (CFone f in openedForm)
                {
                    if (f.number == fr.number)
                    {
                        f.Activate();
                        return true;
                    }
                }
                return false;
            }        private void button1_Click(object sender, EventArgs e)
            {
                CFone one = new CFone("1");
                if (!findForm(one))
                {
                    openedForm.Add(one);
                    one.Show();
                }
            }        private void button2_Click(object sender, EventArgs e)
            {
                CFone two = new CFone("2");
                if (!findForm(two))
                {
                    openedForm.Add(two);
                    two.Show();
                }
            }
        }
    }
    CFone.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace OneFormDemo
    {
        public partial class CFone : Form
        {
            public string number;
            public CFone()
            {
                InitializeComponent();
            }        public CFone(string number)
            {
                this.number = number; 
                InitializeComponent();
            }        private void CFone_FormClosed(object sender, FormClosedEventArgs e)
            {
                Frmmain.openedForm.Remove(this);
            }        private void CFone_Load(object sender, EventArgs e)
            {
                this.Text = this.number;
            }
        }
    }
      

  5.   

    IF 窗口有实例
        show()
    else
       (new  Form())。show
      

  6.   

      private DmmcForm dmmcform;//先设一类级私有字段,在构造函数中初始化为null
           
    private void 基础资料物料ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (dmmcform == null || !dmmcform.Created)
                {
                    dmmcform = new DmmcForm();
                    dmmcform.ActivemdichildForm += new FormEventHandler(editToolStaTxt);
                    dmmcform.MdiParent = this;
                    dmmcform.TableName = "dmmc";
                    dmmcform.Show();
                }
                else
                {
                    dmmcform.Activate();
                }
            }
    //
      

  7.   

    参考愚翁专栏 CSDN第一期总结之一:Form问题Form问题是最基本的问题,因为编写WinApp程序首先接触的对象就是它,因此在论坛中对它而产生的问题也最常见。
    与Form相关的常见问题大致分为如下的四类问题。第一类问题:如何控制窗体的显示顺序;第二类问题:窗体之间的对象如何相互引用或操作;第三类问题:如何处理窗体唯一性问题;最后一个问题:如何合理的关闭窗体或程序。
      

  8.   

    Dictionary forms = new Dictionary()if (forms["好友1"] ==null)  forms["好友1"] = new Form();
    return forms["好友1"];