c# - Winform 自定义控件 : DesignMode doesn't return true whereas in Design Mode

标签 c# winforms

我在这里了解了 DesignMode How to refresh a winform custom control at design time after changing a property

但是当我在我的自定义控件的构造函数中使用它时,它永远不会返回 true,所以当我拖放我的自定义控件时它总是显示 max = 200,这是怎么回事?

if (this.DesignMode)
{                
    this.Min = 0;
    this.Max = 100;
} 
else 
{
    this.Min = 0;
    this.Max = 200;            
}

this.LabMin.Text = this.Min.ToString();
this.LabMax.Text = this.Max.ToString();  

最佳答案

LicenseManager.UsageMode是为此而设计的。

事实上,这是检测控件是否处于设计模式的唯一可靠方法。它只在构造函数期间有效,但它可以很容易地存储在类的一个字段中以供以后引用。

即使容器控件处于设计模式,嵌套控件的 DesignMode 属性也将为 false。

关于c# - Winform 自定义控件 : DesignMode doesn't return true whereas in Design Mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4346361/

相关文章:

c# - 根据 bool 值更改单击时的按钮文本颜色

c# - 使用 INotifyPropertyChanged 绑定(bind)到 Silverlight 中的字典

c# - 如何使用自定义 JsonConverter 仅反序列化 Json.NET 中的子对象?

mysql - 我应该使用哪一个 : MySQL Lite or SQLite?

c# - 您对这种数据库工作有何看法?

c# - 以编程方式构建 MSI

c# - 如何在运行时移除/删除图片框?

c# - 我们可以在 ServicePointManager.SecurityProtocol 中添加四个协议(protocol)吗?

c# - 将 SQL Server 中的数据加载到组合框中

c# - TextBox 可以显示的最大字符数