C# Winforms DataGridView 的视觉继承问题

发布于 2024-09-29 03:12:29 字数 669 浏览 5 评论 0原文

来自此处我创建了一个 BaseForm,然后将其所有 BaseForm.Designer.cs private 成员设置为 protected。然后就有了一个视觉上继承/派生的Form

现在,我可以在设计时调整派生 Form 中除 DataGridView 之外的所有控件的大小或修改。我发现 DataGridView 在派生的 Form 中被锁定,即使它没有在 BaseForm 中锁定。

可能是什么原因?我应该再次寻找/检查什么?

我有一个像这样的基本表单: alt text

我已经派生了一个像这样的表单: 替代文字

From here I have created a BaseForm, then set all its BaseForm.Designer.cs private members to protected. Then has had a visually inherited/derived Form.

Now I am able to re-size or modify all the controls in the derived Form in design-time except the DataGridView. I am finding the DataGridView as locked in the derived Form, even though it is not locked in the BaseForm.

What can be the reason? What should I look/check for again?

I have a base form like this: alt text

And I have derived a form like this: alt text

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

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

发布评论

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

评论(3

赴月观长安 2024-10-06 03:12:29

这是一个已知问题..

https://connect.microsoft.com/VisualStudio/feedback/details/284335/designer-prevents-access-to-protected-datagridview-control-in-inherited-form

您可以创建用户控件类并派生自 DataGridView 类

[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class MyDataGridViewUserControl : DataGridView { }

It is a known problem..

https://connect.microsoft.com/VisualStudio/feedback/details/284335/designer-prevents-access-to-protected-datagridview-control-in-inherited-form

You can create a user control class and derive from DataGridView class

[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class MyDataGridViewUserControl : DataGridView { }
墨小墨 2024-10-06 03:12:29

我猜想 VS 设计器会锁定来自基类的控件。因为您具有相同的初始化代码,所以您将更改基类内部网格的属性,这会影响所有其他派生形式。

如果您想更改网格的属性,我建议为子表单使用单独的网格,因为它的行为应该有所不同。

I guess that VS designer locks controls that came from base classes. Because you have same initialization code you would change properties of grid inside of base class, that affects all other derived forms.

If you want to change properties of your grid, I would recommend to have separate grid for child form, since it should behave differently.

橘香 2024-10-06 03:12:29

这似乎是某些 .NET 控件的问题。
这里有一篇很好的文章:

DataGridView 锁定在继承的 UserControl

It seems an issue with some .NET controls.
There's a good writing here:

DataGridView locked on a inherited UserControl

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