无法以inheritance的forms直观地更改DataGridView
我有一个带有DataGridView
的WinForms表单。 DataGridView
设置为protected
。
当我inheritance该表单时,无法在Visual Studio设计器中更改DataGridView
。 如果我使用Button
执行整个操作,它会按预期工作。
有没有办法来解决这个问题?
一些(剪切的)代码(来自DatagridForm.Designer.cs):
partial class DatagridForm { protected DataGridView dgData; protected Button button; }
从Inherited.cs:
partial class Inherited : DatagridForm { }
这个博客有解决方案:只需创建一个指向正确的设计器内容的inheritance用户控件:
[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))] public class ucInheritedDataGridView : DataGridView { }
奇迹般有效。 唯一的缺点是您无法使用.NET客户端配置文件,因为它不支持System.Forms.Design(您必须添加System.Design
作为参考)。 这不应该是一个太大的问题,因为客户端配置文件无论如何都会被弃用 。
如果您确实需要客户端配置文件,另一种解决方法是将DataGridView
包装在Panel
,您可以移动并调整其大小。