在制表符控件中加载表单 [英] loading forms in tab control

查看:107
本文介绍了在制表符控件中加载表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MainForm我使用RadDock控件(有点选项卡控件),在此控件的第一个选项卡(startpage)中加载了form1

 MainForm() 
{
DocumentWindow DW = new DocumentWindow();
DW.Text = form1;
DW.CloseAction = DockWindowCloseAction.Hide;
Form1 frm1 = new Form1();
frm1 .FormBorderStyle = FormBorderStyle.None;
frm1 .Dock = DockStyle.Fill;
frm1 .TopLevel = false ;
DW.Controls.Add(frm1);
this .radDock1.AddDocument(DW);
this .radDock1.ActiveWindow = DW;
frm1 .Show();
}





现在在Form1的情况下,我想展示form2:

 Form1()
{
Form2 frm2 = new Form2(ParametersToForm2);
frm2 .ShowDialog();
}



但这段代码在新窗口中打开了frm2。如何在MainForm的当前tabcontrol中的新选项卡中显示?



我的解决方案是将ParametersToForm2发送到MainForm的函数,然后此函数调用form2。



 form1()
{
MainForm mfrm = new MainForm(); // 我认为这可以访问此表单的函数,但这会导致新的MainFormWindow不是我想要的
mfrm.showForm2InNewTab(ParametersToForm2);

}





 MainForm()
{
showForm2InNewTab(showForm2InNewTab)
{
DocumentWindow DW = new DocumentWindow();
DW.Text = form2;
DW.CloseAction = DockWindowCloseAction.Hide;
Form2 frm2 = new Form2(ParametersToForm2);
frm2 .FormBorderStyle = FormBorderStyle.None;
frm2 .Dock = DockStyle.Fill;
frm2 .TopLevel = false ;
DW.Controls.Add(frm2);
this .radDock1.AddDocument(DW);
this .radDock1.ActiveWindow = DW;
frm2 .Show();
}
}





但这种方式不显示form2。

解决方案

两件事:

1)主表单的新实例与当前显示的主表单实例不同,与新表单的实例相同汽车与现有汽车不一样。如果你在一辆新车上试驾,并把你的手机放在手套箱里,你打算通过打开旧车的手套箱再次找到它吗?



相反,使用事件:Form1引发一个由它的父主窗体处理的事件,然后Main窗体创建并处理Form2的新实例。



这解释了如何设置事件:转移两种表格之间的信息,第2部分:儿童到父母 [ ^ ]



2)为什么,为什么,你是否在标签页中嵌入表格?为什么不使用UserControl,因为这是他们的设计目的?它更简单,更清洁,你不会得到一堆垃圾...


这是个坏主意。忘记表格,只有一个主要形式。您作为表单,转换为标签页或面板,或作为子项添加到标签页的用户控件的所有内容。



-SA

In a MainForm I'm using a RadDock control (kinda tab control),in first tab of this control(startpage) form1 was loaded

MainForm()
{
 DocumentWindow DW = new DocumentWindow();
            DW.Text = "form1";
            DW.CloseAction = DockWindowCloseAction.Hide;
            Form1 frm1 = new Form1();
            frm1 .FormBorderStyle = FormBorderStyle.None;
            frm1 .Dock = DockStyle.Fill;
            frm1 .TopLevel = false;
            DW.Controls.Add(frm1);
            this.radDock1.AddDocument(DW);
            this.radDock1.ActiveWindow = DW;
            frm1 .Show();
}



now In an event of Form1 I want to show form2:

Form1()
{
Form2 frm2 = new Form2(ParametersToForm2);
frm2 .ShowDialog();
}


but this code opened frm2 in a new window. How can I show that in a new tab in current tabcontrol of MainForm?

my solution was sending "ParametersToForm2"to a function of MainForm and then this function call form2.

form1()
{
    MainForm mfrm=new MainForm();//I defiend this to can access to a function of this form but this causes a new MainFormWindow that is not what I want
     mfrm.showForm2InNewTab(ParametersToForm2);
    
}



MainForm()
{
showForm2InNewTab(showForm2InNewTab)
{
      DocumentWindow DW = new DocumentWindow();
            DW.Text = "form2";
            DW.CloseAction = DockWindowCloseAction.Hide;
            Form2 frm2 = new Form2(ParametersToForm2);
            frm2 .FormBorderStyle = FormBorderStyle.None;
            frm2 .Dock = DockStyle.Fill;
            frm2 .TopLevel = false;
            DW.Controls.Add(frm2);
            this.radDock1.AddDocument(DW);
            this.radDock1.ActiveWindow = DW;
            frm2 .Show();
}
}



but this way doesn't show form2.

解决方案

Two things:
1) A new instance of the Main form is not the same as the currently displayed instance of the Main form, in the same way that a new car is not the same as your existing car. If you go for a test drive in a new car, and put your mobile phone in the glove box, would you expect to find it again by opening the glove box of your old car?

Instead, use events: The Form1 raises an event which is handled by it's "parent" Main form, and the Main form then creates and handles the new instance of Form2.

This explains how to set up the event: Transferring information between two forms, Part 2: Child to Parent[^]

2) Why, oh why, are you embedding forms in tab pages? Why not use a UserControl, since that is what they are designed for? It's simpler, cleaner, and you don't get a load of garbage with it...


This is all the bad idea. Forget about forms, have only one main form. Everything you had as forms, convert to tab pages, or panels, or user controls added as children to tab pages.

—SA


这篇关于在制表符控件中加载表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆