c# - 通过自定义控件 (.NET) 在设计时提供属性

标签 c# .net custom-controls winforms

我创建了一些控件并定义了一些可以在设计时定义的属性,但只显示一个。 另一个问题是,在显示的那个中,显示了表单的文本框,但我无法选择任何内容。

    [Description("Blah Blah Blah"),
    Category("Data"),            
    DefaultValueAttribute(typeof(TextBox), null),
    Browsable(true)]
    //Only show this one
    public TextBox textBox
    {
        set { txt = value;}
    }


    [Description("Blah blah blah again"),
    Category("Data"),
    DefaultValueAttribute(typeof(string), null),
    Browsable(true)]
    public string Mensaje
    {
        set { sMensaje = value; }
    }

所以,我的代码有什么问题

最佳答案

您的属性缺少 setter/getter 。

// Snip attributes
public TextBox textBox
{
    get { return txt; }
    set { txt = value;}
}

// Snip attributes
public string Mensaje
{
    get { return sMensaje; }
    set { sMensaje = value; }
}

关于c# - 通过自定义控件 (.NET) 在设计时提供属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2297492/

相关文章:

c# - 从 List<T> 到数组 T[] 的转换

.net - Azure Functions - ILogger 跨类记录

apache-flex - Adobe Flex - 单击按钮时显示自定义工具提示

c# - 如何确保仅供特定用户下载的链接?

C# 读取格式不正确的 XML 文件

c# - 如何操作整数值的特定数字?

c# - C# 中的自定义 Windows 控件库

c# - 如何使用像字典 <string,Type> 这样的强类型将字符串关联到类

.net - Linq to SQL-不获取特定列

c# - 如何在 C# 中的 FontWeights 之间使用等于运算符?