【问题标题】:Cannot visually change DataGridView in inherited form无法以继承的形式直观地更改 DataGridView
【发布时间】:2013-02-26 12:35:29
【问题描述】:

我有一个带有DataGridView 的 WinForms 表单。 DataGridView 设置为 protected

当我继承该表单时,无法在 Visual Studio 设计器中更改 DataGridView。如果我使用Button 完成所有操作,它会按预期工作。

有没有办法解决这个问题?

一些(剪辑的)代码(来自 DatagridForm.Designer.cs):

partial class DatagridForm {
    protected DataGridView dgData;
    protected Button button;
}

并来自 Inherited.cs:

partial class Inherited : DatagridForm {

}

【问题讨论】:

  • 你能给我们一些代码吗,例如?
  • 添加了一些代码。在Inherited 的设计器中我可以轻松移动的按钮。 DataGridView 被锁定,即使 Locked 设置为 False

标签: c# winforms visual-studio-2010 inheritance


【解决方案1】:

这个blog 有解决方案:只需创建一个指向正确设计器内容的继承用户控件:

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

像魅力一样工作。唯一的缺点是您不能使用 .NET 客户端配置文件,因为它不支持 System.Forms.Design(您必须添加 System.Design 作为参考)。这应该不是什么大问题,因为客户资料是deprecated anyway per 4.5

如果您确实需要客户端配置文件,另一种解决方法是将 DataGridView 包装在 Panel 中,您可以移动和调整其大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    相关资源
    最近更新 更多