Custom Class for dealing with embedding in Forms

后端 未结 3 936
盖世英雄少女心
盖世英雄少女心 2020-12-11 11:35

I have a custom class file in C# that I inherited and partially extended. I am trying to re factor it now as I have just enough knowhow to know that with something

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 12:17

    You don't need generic to do this:

    public static void ShowFormInControl(Control ctl, Form frm) {
      frm.TopLevel = false;
      frm.FormBorderStyle = FormBorderStyle.None;  // Others rarely make sense
      frm.Dock = DockStyle.Fill;
      frm.Visible = true;
      ctl.Controls.Add(frm);
    }
    

    Sample usage:

    public Form1() {
      InitializeComponent();
      ShowFormInControl(this.panel1, new Form2());
    }
    

提交回复
热议问题