C#中单个表单上的多个屏幕 [英] Multiple screens on single form in C#

查看:134
本文介绍了C#中单个表单上的多个屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我们所知道的,开发GUI非常重要,我正在为一个项目开发一个配置模块,其中包含许多设置,例如用户设置,软件设置,字体设置.

对于每种设置,我采用了不同的形式.我有以下菜单:

设置
-用户设置
-软件设置
-字体设置

在子菜单项的每次单击上,我都将重定向到相应的表单.

取而代之的是,我们可以以单一形式进行操作,用户将选择适当的选项,并相应地更改屏幕.就像我们在每个选项卡上都具有选项卡一样,单击屏幕会以单一形式更改.

就像我们在Visual Studio中转到项目的项目"属性一样.

任何人都可以提出一种方法来实现单一表单吗?

谢谢和问候,
约瑟夫.

Hello,

All we know that developing a GUI is very important, i was developing a configuration module for a project into that there were many settings like user setting, software setting, font setting.

For each setting i had taken separate forms. I had a following menu:

Setting
- User Setting
- Software Setting
- Font Setting

On each click of sub-menu item i am redirecting to respective form.

Instead can we do in single form where user will select appropriate option and accordingly besides screen will be changed. Like we have tabs on every tab click screen changes on single form.

Like when we go to Project properties of project in visual studio.

Can any one suggest a way to do it single Form?

Thanks and Regards,
Joseph.

推荐答案

为什么不使用制表符控件?这是我最常看到的.或者,您可以堆叠面板,并且子菜单控件可以将正确的面板置于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 ;-)


这篇关于C#中单个表单上的多个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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