如何在 C# 中创建树视图首选项对话框类型的界面? [英] How to create a tree-view preferences dialog type of interface in C#?

查看:30
本文介绍了如何在 C# 中创建树视图首选项对话框类型的界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基本上只是一个首选项对话框的应用程序,很像 Visual Studio 本身使用的树视图首选项对话框.该应用程序的功能只是将数据从串行设备传递到文件.在将数据写入文件之前,它会对数据执行很多很多转换,因此应用程序的 GUI 只是指示这些转换应该是什么的所有设置.

I'm writing an application that is basically just a preferences dialog, much like the tree-view preferences dialog that Visual Studio itself uses. The function of the application is simply a pass-through for data from a serial device to a file. It performs many, many transformations on the data before writing it to the file, so the GUI for the application is simply all the settings that dictate what those transformations should be.

设计/编码树视图首选项对话框的最佳方法是什么?我一直在做的方法是构建主窗口,左侧有一个停靠的树控件.然后我一直在创建对应于树的每个节点的容器控件.当一个节点被选中时,应用程序将该节点对应的容器控件带到最前面,将其移动到正确的位置,并在主窗口中将其最大化.在设计它时,这看起来非常非常笨拙.这基本上意味着在设计时我在主窗口边缘之外有大量容器控件,我必须不断滚动主窗口才能使用它们.我不知道我写这篇文章的方式是否完全有意义,但也许我所谈论的这种视觉效果会更有意义:

What's the best way to go about designing/coding a tree-view preferences dialog? The way I've been going about it is building the main window with a docked tree control on the left. Then I have been creating container controls that correspond to each node of the tree. When a node is selected, the app brings that node's corresponding container control to the front, moves it to the right position, and maximizes it in the main window. This seems really, really clunky while designing it. It basically means I have tons of container controls beyond the edge of the main window during design time that I have to keep scrolling the main window over to in order to work with them. I don't know if this totally makes sense the way I'm writing this, but maybe this visual for what I'm talking about will make more sense:

基本上我必须使用这个巨大的表单,到处都是容器控件,然后进行大量的运行时重新格式化以使其全部工作.这看起来像是很多额外的工作.我是否以一种完全愚蠢的方式这样做?是否有一些我缺少的明显"更简单的方法来做到这一点?

Basically I have to work with this huge form, with container controls all over the place, and then do a bunch of run-time reformatting to make it all work. This seems like a lot of extra work. Am I doing this in a totally stupid way? Is there some "obvious" easier way of doing this that I'm missing?

推荐答案

更简洁的方法是为每个窗格"创建单独的表单,并在每个表单构造函数中设置

A tidier way is to create separate forms for each 'pane' and, in each form constructor, set

this.TopLevel = false;
this.FormBorderStyle = FormBorderStyle.None;
this.Dock = DockStyle.Fill;

这样,这些表单中的每一个都可以在自己的设计器中布局,在运行时实例化一次或多次,然后像普通控件一样添加到空白区域.

That way, each of these forms can be laid out in its own designer, instantiated one or more times at runtime, and added to the empty area like a normal control.

也许主表单可以在一个面板中使用带有静态 TreeViewSplitContainer,并在另一个面板中使用空间来添加这些表单.添加后,可以使用 Hide/ShowBringToFront/SendToBack 方法翻转它们.

Perhaps the main form could use a SplitContainer with a static TreeView in one panel, and space to add these forms in the other. Once they are added, they could be flipped through using Hide/Show or BringToFront/SendToBack methods.

SeparateForm f = new SeparateForm(); 
MainFormSplitContainer.Panel2.Controls.Add(f); 
f.Show();

这篇关于如何在 C# 中创建树视图首选项对话框类型的界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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