我可以在设计时更改继承控件的属性吗?

发布于 2024-07-15 10:03:28 字数 146 浏览 2 评论 0原文

我正在使用视觉继承,并且想知道是否有一种方法可以在设计时(最好是在表单设计器中)更改继承控件的属性。 如果没有,则在设计器代码中。

我在基类中将控件声明为 Public。 我可以在子表单代码中访问它,但不能在表单设计器中访问它。 这是不可能的吗?

I am using visual inheritance and was wondering if there is a way to change the properties of inherited controls at design time, preferably in the form designer. If not, then in the designer code.

I have my control declared as Public in the base class. I can access it in the child form code, but not in the form designer. Is this just not possible?

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

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

发布评论

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

评论(3

乙白 2024-07-22 10:03:28

Visual Studio 中对于视觉继承存在一些限制。 遗憾的是,派生表单\用户控件无法修改包含基础集合的控件,即 DataGridViewRows、ToolStrips、ListViewColumns 等。

Microsoft Bug 报告

在某些情况下,有一些方法可以解决此问题。 在基类中创建一个受保护的属性,该属性公开要修改的控件的确切属性(DataGridView.BackgroundColor 或 ListView.Columns)。

您的基本表单应该能够访问此属性以更改所需的组件。 我已经成功地为 ListView.Columns 和 DataGridView.rows 完成了此操作,但是 ToolStrip.Items 不起作用。

There are limitations placed within visual studio for visual inheritance. Unfortunately, derived forms\usercontrols cannot modify controls containing collections within the base, namely DataGridViewRows, ToolStrips, ListViewColumns, etc.

Microsoft Bug Report

There are ways around this in certain situations. Create a protected property in the base class that exposes the exact properties of the control you wish to modify (DataGridView.BackgroundColor, or ListView.Columns).

Your base form should be able access this property to change the components needed. I've done this for ListView.Columns, and DataGridView.rows successfully, however ToolStrip.Items would not work.

酸甜透明夹心 2024-07-22 10:03:28

它似乎只适用于某些控件,但不适用于所有控件,我不明白为什么。 在我的基本窗体上,我有一个 TabControl,其中包含一个 ComboBox、一个 ToolStrip 和一个 DataGridView。 它们都设置为 Public,但我只能修改 ComboBox 的属性,而不能修改其他两个控件的属性。

我不知道这是为什么。

It seems to work only for certain controls, but not all and I can't understand why. On my base form I have a TabControl that within it is a ComboBox, a ToolStrip, and a DataGridView. All of them are set to Public, but I can only modify the properties of the ComboBox and not the other two controls.

I have no idea why this is.

水染的天色ゝ 2024-07-22 10:03:28

您需要更改控件的可见性。 将控件属性 Modifiers 设为 public 并重新编译项目,然后就可以更改继承的控件的属性。

You need to change your control visibility. Put the control property Modifiers on public and recompile the project and then you can change properties of the inherited control.

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