处理多个视图/选项卡式 GUI 元素的最佳方法是什么

发布于 2024-07-22 02:18:58 字数 335 浏览 6 评论 0原文

我正在开发一个应用程序,该应用程序可以根据正在查看的对象向用户提供各种数据。 这些对象都具有相同的接口,只是具有超出曾经区分的扩展属性。

我正在寻找向用户显示依赖于类型的控件的“最佳”方法。 我想使用选项卡,但我坚持使用 .NET 2.0,据我所知,隐藏/显示选项卡的唯一方法是删除它们并重新添加它们。 这可能是最好的方法,但这会导致 GUI 组件闪烁、重新加载时在活动选项卡上保留选项卡等问题。

我可以为每个控件制作自定义控件,或者将它们全部加载并在必要时隐藏/显示(这我过去曾在项目上做过),或者处理并重新实例化它们......

为了最好地澄清,我会说代码优雅和程序效率之间最接近的平衡。

I'm working on an application that presents the user with varied data, depending on the object being viewed. The objects are all of the same interface just with extended properties beyond once distinguished.

I'm looking for the "best" way to display a type-dependent control to the user. I would like to use tabs but I'm stuck with .NET 2.0 and from what I can gather the only way to hide/show tabs are to remove them and re-add them. That might be the best way but that leads to issues regarding blinking of the GUI components, keeping tabs on the active tab when reloading, etc.

I could make custom controls for each and either have them all loaded and hide/show when necessary (which I have done in the past on projects), or dispose and re-instantiate them...

To clarify best, I would say the closest balance between code elegance and program efficiency.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鸠书 2024-07-29 02:18:58

我已经使用过并且非常幸运地加载了所有这些,然后显示/隐藏了所需的。

处理和重新实例化所有东西总是让事情变得非常混乱。

为了不让加载时间变得可怕,您可以在第一次使用时实例化它们。 就像是:

IView LoadView(Type dependantType)
{
  // get the view or create one
  IView view = GetView(dependantType);
  if (view == null)
  {
    view = InstantiateViewAndAddToForm(dependantType);
    AddView(view);
  }

  //
  // do some binding to your model or whatever here
  //

  // make the correct view visible
  foreach (IView v in Views)
    view.Visible = v == view;
}

I have used and have had the best luck with loading them all and then showing/hiding the ones needed.

Disposing and re-instantiating everything always made things very messy.

In order to not have load time be horrible, you can instantiate them on first use. Something like:

IView LoadView(Type dependantType)
{
  // get the view or create one
  IView view = GetView(dependantType);
  if (view == null)
  {
    view = InstantiateViewAndAddToForm(dependantType);
    AddView(view);
  }

  //
  // do some binding to your model or whatever here
  //

  // make the correct view visible
  foreach (IView v in Views)
    view.Visible = v == view;
}
你的往事 2024-07-29 02:18:58

您能否为每个对象创建一个面板,并使用一个字典将对象类型和面板关联起来?

您可以告诉面板如果尺寸相同则将其置于前面,或者将所有 Panels.Visible 设置为 false,然后将您需要的面板设置为 true。

Could you just create a panel for each object and have a dictionary associate the object type and the panel?

You could just tell the panel to bring to front if they are all the same size, or set all Panels.Visible to be false, and just set the one you need to be true.

星光不落少年眉 2024-07-29 02:18:58

我已将 DockPanel Suite 用于需要多个选项卡的应用程序。
它是一个开源项目,因此您可以根据需要实际修改代码。

该套件有很多功能,但是,如果您只能使用选项卡的话。

I have used DockPanel Suite for applications that require multiple tabs.
It is an open source project, so you can actually modify the code if you wish.

The Suite has many functions, however, if you can just use the Tabs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文