自定义了一个控件
其中有一个 自定义的属性 bgColor [
Category("BgColor"),
Description("背景色")
]
public Color BgColor
{
get
{
return bgColor;
}
set
{
bgColor = value;
Invalidate();
}
}把控件放到 form上可以显示这个属性,但是无法选择颜色如何让这个自定义的属性也可以 选择颜色?

解决方案 »

  1.   

    继承Control本身就有背景颜色的属性
      

  2.   

    winform中
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication2
    {
        public partial class CustomControl1 : Control
        {
            public CustomControl1()
            {
                InitializeComponent();
            }        protected override void OnPaint(PaintEventArgs pe)
            {
                // TODO: 在此处添加自定义绘制代码            // 调用基类 OnPaint
                base.OnPaint(pe);
            }
            Color _color;
            public Color BgColor
            {
                get
                {
                    return _color;
                }
                set
                {
                    _color = value;
                }
            }
        }
    }
    这样测试可以满足lz要求
      

  3.   

    覆盖不行么?
    public new Color BackColor
    {
    ...
    }
      

  4.   

    to greennetboy(我的老婆叫静静) ( ) 你写得可以?那我这里怎么还是显示 (none),而且没有出现颜色的选择项
      

  5.   

    恩,好像可以了
    但如果是组合属性呢?例如 有一个渐变色的属性 包含color1,color2这样两个值
    就像定义字体一样有多个选项, 前面带 + 号的属性,该怎么写?
      

  6.   

    class AAA : ExpandableObjectConverter 
    {
    public Color c1
    {
    get
    set
    }
    public Color c2
    {
    get
    set
    }}
      

  7.   

    需要继承一下类型转换器,代码在msdn上可以查询得到。
      

  8.   

    : ExpandableObjectConverter 
    是哪一个using
      

  9.   

    是 System.ComponentModel.ExpandableObjectConverter 这个不?