PropertyGrid 的替代品?请听我说完

发布于 2024-09-26 18:54:17 字数 786 浏览 5 评论 0原文

我知道这是一个广泛的话题,但请听我说完。

我有一些需要编辑一组相关属性的实例。有些是自由文本,另一个可能是整数或密码,还有更多具有预定义的选项(选择框)。我基本上需要一个容器,它在左侧重复文本行,在右侧有一个控件。

我无法使用 PropertyGrid,因为我并不总是有实例,而且我在理解它想要的所有 ipropertyeditorservice 属性和帮助程序方面遇到了一些困难。

我无法使用 DataGrid 或 DataGridView 因为它们是基于列的。每行可能需要不同类型的控件,因此充满任何一种控件类型的列都是无用的。

我尝试扩展 ListView,这就是我现在陷入困境的地方。它的所有者绘制并在第二列的边界内绘制控件。看起来没问题,但是微软的固定行高是个问题。我认为它超出了图像列表或字体,甚至文本框和组合框也无法同意以相同的方式调整自身大小,而忘记了复选框或其他任何内容。我的意思是,在我的特定桌面设置上,单行控件通常看起来不错,但我无法控制每个分辨率的重叠。

我自己想出的唯一另一个想法(除了放弃或从 System.Windows.Forms.Control 派生一些非标准和丑陋的东西之外)是将所有这些子控件塞入 TableLayoutContainer 中。它主要解决了奇怪的高度问题,但我失去了 ListView 的标题和滚动功能。

几周来我一直在寻找替代方案,但一直找不到。每个人都重新发明了 datagridview 和 listview-as-datagrid,甚至是商业解决方案。我不敢相信没有一个简单的替代品可以替代 PropertyGrid 的功能。我的 ListView 是很多不好的列表中最好的......我还能做什么?

I know this is a wide topic, but please hear me out.

I have a few instances where I need to edit a set of related properties. Some are free text, another might be an integer or password, and many more have predefined options (a selectbox). I basically need a container that repeats rows of text on the left with a control on the right.

I can't use a PropertyGrid because I don't always have an instance and I have been having some difficulty understanding all of the ipropertyeditorservice attributes and helpers it wants.

I couldn't use a DataGrid or DataGridView because they're column based. Every row may need a different type of control, so a column full of any one control type is useless.

I tried extending the ListView which is where I'm stuck right now. It's owner drawn and draws the controls within the bounds of the second column. It looks OK, but Microsoft's fixed row height is a problem. I think it goes off the imagelist or the font, which even textbox and combobox can't agree on to size themselves the same way and forget about a checklistbox or anything else. I mean it usually looks OK for single-line controls on my specific desktop settings but I can't control the overlap at every resolution.

The only other idea I've come up with on my own (aside from giving up or deriving something non-standard and ugly from System.Windows.Forms.Control) is to jam all of these subcontrols into a TableLayoutContainer. It fixes the weird height problem mostly but I lose the header and scrolling features of ListView.

I've been looking for an alternative for weeks and I just can't find any. Everybody's reinvented the datagridview and the listview-as-datagrid, even the commercial solutions. I can't believe there isn't a simple replacement out there for what the PropertyGrid does. My ListView is the best of alot of bad lot...what else can I do?

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

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

发布评论

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

评论(3

相守太难 2024-10-03 18:54:17

尝试使用 TableLayoutPanel

Label l1 = new Label();
Label l2 = new Label();
Label l3 = new Label();
Label l4 = new Label();
l1.Text = "Name";
l2.Text = "Color";
l3.Text = "Quantity";
l4.Text = "Notes";
TextBox c1 = new TextBox();
ComboBox c2 = new ComboBox();
NumericUpDown c3 = new NumericUpDown();
TextBox c4 = new TextBox();
c2.Items.AddRange(new string[] { "Red", "Green", "Blue" });

//tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
//tableLayoutPanel1.AutoScroll = true;
tableLayoutPanel1.AutoSize = true;
tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
int rowIndex = 0;
tableLayoutPanel1.SuspendLayout();
foreach (Control[] pair in new Control[][] {
   new Control[] {l1, c1},
   new Control[] {l2, c2},
   new Control[] {l3, c3},
   new Control[] {l4, c4}})
{
   tableLayoutPanel1.Controls.AddRange(pair);
   if (tableLayoutPanel1.RowStyles.Count <= rowIndex)
      tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
   else
      tableLayoutPanel1.RowStyles[rowIndex++].SizeType = SizeType.AutoSize;
}
tableLayoutPanel1.ResumeLayout();

Try using a TableLayoutPanel

Label l1 = new Label();
Label l2 = new Label();
Label l3 = new Label();
Label l4 = new Label();
l1.Text = "Name";
l2.Text = "Color";
l3.Text = "Quantity";
l4.Text = "Notes";
TextBox c1 = new TextBox();
ComboBox c2 = new ComboBox();
NumericUpDown c3 = new NumericUpDown();
TextBox c4 = new TextBox();
c2.Items.AddRange(new string[] { "Red", "Green", "Blue" });

//tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
//tableLayoutPanel1.AutoScroll = true;
tableLayoutPanel1.AutoSize = true;
tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
int rowIndex = 0;
tableLayoutPanel1.SuspendLayout();
foreach (Control[] pair in new Control[][] {
   new Control[] {l1, c1},
   new Control[] {l2, c2},
   new Control[] {l3, c3},
   new Control[] {l4, c4}})
{
   tableLayoutPanel1.Controls.AddRange(pair);
   if (tableLayoutPanel1.RowStyles.Count <= rowIndex)
      tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
   else
      tableLayoutPanel1.RowStyles[rowIndex++].SizeType = SizeType.AutoSize;
}
tableLayoutPanel1.ResumeLayout();
鯉魚旗 2024-10-03 18:54:17

您是否尝试过“VisualHint”属性网格替换?作为信息,对于灵活的属性绑定,如果您不想了解 system.componentmodel 的内部结构,DataTable 会非常方便

Have you tried the "VisualHint" property grid replacement? For info, for flexible property binding DataTable can be quite handy if you don't want to learn the guts of system.componentmodel

筱武穆 2024-10-03 18:54:17

我遇到了你的问题两次,

第一次,我继承了ListBox控件并创建了自己的控件,这不是一件容易的事,我在布局、聚焦事件、鼠标滚轮等方面遇到了一些问题。

第二次,我使用了 PropertyGrid 控件,但是如果类中的值发生更改,我在隐藏和禁用某些字段方面也遇到了一些问题,

我想,如果我再次需要该控件,我将使用第三个party control,有很多,我想ComponentOne有一个,

祝你好运。

I had your problem twice,

The first time, I inherited from ListBox control and created my own control, it was not an easy task, I had some problems with the layout, focusing events, mouse wheel and other.

In the second time, I used the PropertyGrid control, but I had also some problems in hiding and disabling some fields if a value has changed in the class,

I think, if I'll need the control again, I'll use a third party control, there're many, I think ComponentOne has one,

Good luck.

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