c# - 在设计器中显示 UserControl 的公共(public)字段

标签 c# winforms visual-studio user-controls

我正在尝试将一些字段添加到我正在制作的自定义 UserControl 中。我有一些字段,我希望它们在 Visual StudioProperties 窗口中可见。我尝试使用下面的标志,但我没有在设计器中看到该字段,即使在编译之后也是如此。

我应该如何正确执行此操作?

public partial class TosChartControl: UserControl
{

    #region PUBLIC FIELDS

    [Browsable(true)] //Added this but still does not show up
    [Category("Data")]
    [DefaultValue(0)]
    [Description("ID of the Sensor Node")]
    public int NodeId { get; set; }

    #endregion

    public TosChartControl()
    {
        InitializeComponent();
    }
}

我确实清理并重建了解决方案和项目,但我仍然无法在“属性”窗口中看到该字段。甚至重新启动 Visualstudio 也无济于事。

最佳答案

更新:您的公共(public)属性只有在设计器中的另一个控件中时才在设计器中可见。事实证明,您不需要 添加此属性,默认情况下属性在设计器中可见。据我了解,当它位于另一个组件的设计 View 中时,将创建用户控件的实例并显示属性。抱歉一开始误导大家了,我觉得有必要加上。


试试这个属性:

[Browsable(true)]

http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx

关于c# - 在设计器中显示 UserControl 的公共(public)字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17447684/

相关文章:

javascript - 在 ASP.NET C# 中获取 StackOverFlow 异常

c# - 等待数组;通过实现数组的扩展方法

c# - 如何使 ListView 中的项目具有不同的颜色?

visual-studio-2010 - 如何在visual studio中比较两个文件而忽略大小写

c# - 在没有参数化查询的情况下防止 SQL 注入(inject)?

c# - 如何使用 Google Docs C# API 访问公共(public)电子表格?

c# - WinForm 设置未保存

c# - 文本框填充

c# - 如何打包和部署带有符号和源代码的 NuGet 包,以便调试器可以使用该源代码?

c++ - 预编译头是递归的吗?