且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#中单个表单上的多个屏幕

更新时间:2023-12-06 12:07:10

为什么不使用制表符控件?这是我最常看到的.或者,您可以堆叠面板,并且子菜单控件可以将正确的面板置于z顺序的顶部.
Why not use a tab control? This is what I''ve seen most commonly. Or you could stack panels and your submenu control could bring the correct panel to the top of the z-order.


做一件事情,制作一个面板,然后制作用户控件表单,而不是Forms.选择特定的菜单项时,使面板可见,以便它们以相同的形式显示.根据您的选择使特定的用户控件可见.

一小段代码

//在菜单下选择项目

Do one thing make a panel and make user control forms instead Forms. Make the panel as visible when particular Menu item selected so that they will be shown in the same form. Make particular user control visible based on your selection.

A small code

//Under Menu selected Item

<code></code>     pnlACH.Controls.Clear();//Panel
                       pnlACH.Visible = true;
                       UserControl usrcntrlfileheader = new UsrCntrlFileHeader();//User Control
                      usrcntrlfileheader.Show();
                      pnlACH.Controls.Add(usrcntrlfileheader);



像这样加载相应的用户控件.



Like this load the corresponding user control.


使用类似Panel s之类的东西.像其他程序员之前指出的那样,将它们堆叠起来.但是不要在一个类中全部设计它们.
创建基类:
Use something like Panels. Stack them, as pointed before by a fellow programmer. But don''t design them all in a class.
Create a base class:
public class MyTab : UserControl


然后,在各个文件中制作和设计各个选项卡:


Then, make and design your individual tabs in individual files:

public sealed class MyFirstTab : MyTab


public sealed class MySecondTab : MyTab


等等...
最后,在您的Form:


And so on...
Finally, in your Form:

private List<MyTab> myTabs = new List<MyTab>();


将选项卡添加到List:


Add the tabs to the List:

myTabs.Add(new MyFirstTab());
myTabs.Add(new MySecondTab());
//...


并将它们添加到Form:


And add them to the Form:

this.Controls.AddRange(myTabs.ToArray());


因此,当您需要其中之一时,只需记住其序号即可. (如果要优化它,可以将它们存储在Dictionary<string, MyTab>中,并按名称引用它们)


So, when you need one of them, you just have to remember its ordinal number. (If you want to refine it, you may store them in a Dictionary<string, MyTab> and refer them by name instead)

myTabs[index].BringToFront();


希望有帮助.
一个接受答案也对我有帮助;-)


Hope that helps.
An Accept Answer helps me too ;-)