在tabControls tabPage内更改和传递内容 [英] Changing and passing content inside tabControls tabPage

查看:27
本文介绍了在tabControls tabPage内更改和传递内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows窗体应用程序中工作,并且有以下问题.我在应用程序中使用tabControl,并且当用户执行特定操作时,有必要在某些tabPages中更改内容.

I am working in windows forms application and have a following issue. I use tabControl in my application and there is a need to change a content inside certain tabPages when users perform specific actions.

tabPage其中包含一个文本区域和一个按钮,当用户单击文本区域内的按钮信息时,应该以某种方式存储它,并且相同的tabPage应该显示新内容,例如更多的文本区域,按钮等,我认为可以通过使用其中的视图来简化操作,因此可以隐藏一个视图,而可以显示另一个视图.

for example tabPage one contains a text area and a button, when user clicks button information inside a text area should be stored somehow, and that same tabPage should display new content e.g. more text areas, buttons etc, I assume it is easier to do by using views inside it, so one view can be hidden and another can be shown.

推荐答案

这在一定程度上与口味有关.您可以选择一种方法显示或隐藏控件,也可以将它们分组到一个UserControl中,然后在一个命令中显示或隐藏.

This a to a degree a matter of taste. You can chose to show and hide controls one by one in a method or you can group them in a UserControl which you then show or hide in one command.

我会通过以下问题以一种或另一种方式来做出决定:

I would base my decision one way or the other by these questions:

  • 是否存在控件,这些控件将始终可见,并且这些控件的布局如何?

  • Are there controls, that will always be visible and how is the layout for these?

有多少个控件可以显示/隐藏?

How many controls are there to show/hide?

是否需要重用您的一个或多个视图?

Is there a need to reuse one or more of your views?

最后一个问题可能会产生很大的不同:如果要重复使用,请使用 UserControl .基本上就是这样做:组控件,就像表单一样.

The last question may make the big difference: If you want re-use, do go for the UserControl. It is basically meant to do just that: Group controls, like a form does.

对于仅几个控件(在switchViewMode方法中)一个接一个地做到这一点,imo.

For just a few controls doing it in a one by one (in a switchViewMode-method) would suffice, imo.

要添加UC,请在project-explorer中的项目上单击鼠标右键,然后选择 add-usercontrol .然后选择好的名称,例如UC_Goods或UC_Services或您的商店政策建议的名称.

To add UCs you right-click your project in the project-explorer and chose add - usercontrol. Then chose a nice name, like UC_Goods or UC_Services or whatever your shop policy suggests.

然后,您会看到空白的GUI.现在添加所需的控件.

You are then presented with the empty GUI. Now add the controls you need.

在这里要做出一个决定:如果要重用它,请确保控件获得通用名称!如果没有,那没关系.原因是,当您添加同一UC的两个实例时,它们的控件将具有相同的名称,并且您必须由父级(UC)来限定它们的作用

Here a decision is to be made: If you will reuse it make sure the controls get generic names! If not it doesn't matter. The reason is, that when you add two instances of the same UC, their controls will have the same names and you will have to qualify them by the parent (the UC)

在这里您还可以编写事件脚本等.

Here you also script events etc..

最后根据需要将实例添加到TabPage中:

Finally add instances to the TabPage as need like this:

public UC_Goods uc_goodsDelivered = new UC_Goods();
public UC_Goods uc_goodsOnHold = new UC_Goods();
public UC_Services uc_ItServices = new UC_Services ();

public Form1()
{
  InitializeComponent();
  tab.tp_goodsPage.Controls.Add(uc_goodsDelivered);
  tab.tp_goodsPage.Controls.Add(uc_goodsOnHold);
  goodsOnHold.Hide();
  tab.tp_goodsPage.Controls.Add(uc_ItServices);
  uc_ItServices .Hide();
  // take care of dock style or anchors..
  // ..and initialzing fields..
}

这将分别声明两个UC类以及每个的两个和一个实例.只有一个可见.由于一类被使用两次,因此在您限定其名称之前,其控件具有不明确的名称,例如像这样: uc_goodsDelivered.Status ...

This delclares two UC classes and two and one instance of each respectively. Only one is visible. Since one class is used twice its controls have ambigous names until you qualify them e.g. like this: uc_goodsDelivered.Status...

hth

这篇关于在tabControls tabPage内更改和传递内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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