Bar*_*chs 4 c# inheritance visual-studio-2010 winforms
我有一个WinForms表单,上面有一个DataGridView.该DataGridView设置为protected.
当我继承该表单时,无法DataGridView在Visual Studio设计器中更改它.如果我用a做整件事Button,它会按预期工作.
有没有办法来解决这个问题?
一些(剪切的)代码(来自DatagridForm.Designer.cs):
partial class DatagridForm {
protected DataGridView dgData;
protected Button button;
}
Run Code Online (Sandbox Code Playgroud)
从Inherited.cs:
partial class Inherited : DatagridForm {
}
Run Code Online (Sandbox Code Playgroud)
这个博客有解决方案:只需创建一个继承的用户控件,指向正确的设计器内容:
[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class ucInheritedDataGridView : DataGridView { }
Run Code Online (Sandbox Code Playgroud)
奇迹般有效.唯一的缺点是您无法使用.NET客户端配置文件,因为它不支持System.Forms.Design(您必须添加System.Design作为参考).这不应该是一个太大的问题,因为客户端配置文件无论如何都会被弃用.
如果你真的需要在客户端配置文件,另一个解决办法是包裹DataGridView在Panel,您可以移动和调整大小.
| 归档时间: |
|
| 查看次数: |
2798 次 |
| 最近记录: |