Сategory和提示不起作用

时间:2015-08-18 12:13:24

标签: c# winforms propertygrid

我的应用程序上有一个属性网格,我为它创建了以下类:

class NginXConfig
{
    [Browsable(true)]
    [ReadOnly(true)]
    [Category("General")]
    [Description("Defines the number of worker processes. Windows only supports one.")]
    int _worker_processes = 1;
    public int worker_processes
    {
        get { return _worker_processes; }
        set { _worker_processes = value; }
    }

    [Browsable(true)]
    [ReadOnly(false)]
    [Category("General")]
    [Description("Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes.")]
    int _worker_rlimit_nofile = 100000;
    public int worker_rlimit_nofile
    {
        get { return _worker_rlimit_nofile; }
        set { _worker_rlimit_nofile = value; }
    }

    [Browsable(true)]
    [ReadOnly(false)]
    [Category("General")]
    [Description("Defines the error logging level. Availble options: debug | info | notice | warn | error | crit | alert | emerg")]
    string _error_log_level = "crit";
    public string error_log_level
    {
        get { return _error_log_level; }
        set { _error_log_level = value; }
    }
}

在属性网格上,当我设置SelectedObject时 - 它呈现如下:

enter image description here

  1. 我没有显示我定义为“常规”的类别。它显示为“杂项”。

  2. 提示Description未显示。

  3. 是否可以通过课程定义这些字段在我的媒体资源网格中的显示顺序?

  4. 修改

    此问题现已解决。这是我班级的工作版本:

    class NginXConfig
    {
        [Browsable(true), ReadOnly(true), Category("General"), DefaultValueAttribute(1), Description("Defines the number of worker processes. Windows operating system supports only one.")]
        public int worker_processes { get ; set; }
    
        [Browsable(true), ReadOnly(false), Category("General"), DefaultValueAttribute(10000), Description("Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes.")]
        public int worker_rlimit_nofile { get; set; }
    
        [Browsable(true), ReadOnly(false), Category("General"), DefaultValueAttribute("crit"), Description("Defines the error logging level. Availble options: debug | info | notice | warn | error | crit | alert | emerg")]
        public string error_log_level { get; set; }
    
        public NginXConfig()
        {
            worker_processes = 1;
            worker_rlimit_nofile = 10000;
            error_log_level = "crit";
        }
    }
    

1 个答案:

答案 0 :(得分:2)

以这种方式定义:

int _worker_processes = 1;

[Browsable(true),ReadOnly(true),Category("General"),Description("Defines the number of worker processes. Windows only supports one.")]
public int worker_processes
{
    get { return _worker_processes; }
    set { _worker_processes = value; }
}

属性适用于属性,不适用于私有变量。为什么{ get; set; }没有int _worker_processes = 1;