Winform中自定义控件,BackColor,ForeColor系统选择窗口

        /// 
        /// 正常时的前景色,若不设置,以ForeColor为准
        /// 
        private Color _normalForeColor = Color.Empty;
        [Category("自定义外观"),
         //DispId(NativeMethods.ActiveX.DISPID_FORECOLOR),DISPID_FORECOLOR = unchecked((int)0xFFFFFDFF);
         DispId(unchecked((int)0xFFFFFDFF)),
         Description("正常时的前景色,若不设置,以ForeColor为准")]
        public Color NormalForeColor
        {
            get { return _normalForeColor; }
            set
            {
                _normalForeColor = value;
                if (value != Color.Empty || value!=Color.Transparent)
                {
                    this.ForeColor = value;
                }
            }
        }

Winform中自定义控件,BackColor,ForeColor系统选择窗口_第1张图片想用系统的这个选择工具,加上代码 DispId(unchecked((int)0xFFFFFDFF))即可

在源码中,ForeColor   -》  DispId(NativeMethods.ActiveX.DISPID_FORECOLOR),但由于NativeMethods.ActiveX.DISPID_FORECOLOR访问级别不够,直接找到定义的int来替代

BackColor-》 DispId(NativeMethods.ActiveX.DISPID_BACKCOLOR)

public const int DISPID_BACKCOLOR = unchecked((int)0xFFFFFE0B);

你可能感兴趣的:(C#基础)