本文介绍了按钮上的选项卡控件中打开Windows窗体单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Button上打开一个Windows窗体。在一个Tabcontrol上。

我该怎么办?

我的COde就像....... ..................................

........ .................................................. .............................

if(e.Node.Name ==Node1)

{

TabPage tbp = new TabPage();

childForm.TopLevel = false;

tabControl1.TabPages .Add(tbp);

tbp.Controls.Add(childForm);

tbp.Text =Main;

//已添加表格到标签页

childForm.WindowState = FormWindowState.Maximized;

//如果此页面已经打开............. />
if(childForm.IsHandleCreated == true)

{

tabControl1.Focus();

tabControl1.TabPages [ TBP ] .Show();

tabControl1.TabPages [tbp]。选择();



}

else

{



childForm.Show();



}

......................................... .......................................

但这是给出错误....对象未设置为Object的实例

I want to open a windows form on Button click.in a Tabcontrol.
How should I do?
My COde Is Like.........................................
.......................................................................................
if (e.Node.Name == "Node1")
{
TabPage tbp = new TabPage();
childForm.TopLevel = false;
tabControl1.TabPages.Add(tbp);
tbp.Controls.Add(childForm);
tbp.Text = "Main";
//Added form to tabpage
childForm.WindowState = FormWindowState.Maximized;
//if this page is Already Open.............
if (childForm.IsHandleCreated == true)
{
tabControl1.Focus();
tabControl1.TabPages["tbp"].Show();
tabControl1.TabPages["tbp"].Select();

}
else
{

childForm.Show();

}
................................................................................
but this is giving error....Object not set to instance of Object

推荐答案

Form2 frm = new Form2();  //Or whatever your form is called
frm.Show(this);



或(如果你想以模态方式打开它):


or (if you want to open it modally):

Form2 frm = new Form2();  //Or whatever your form is called
frm.ShowDialog(this);


private void button1_Click(object sender, EventArgs e)
{
    Form2 frm = new Form2();
    frm.TopLevel = false;
    tabPage1.Controls.Add(frm);
    frm.Dock = DockStyle.Fill;
    frm.Show();
}



这篇关于按钮上的选项卡控件中打开Windows窗体单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 21:56