欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#構(gòu)造ColorComboBox(顏色下拉框)

 更新時間:2013年12月09日 11:18:02   作者:  
這篇文章主要介紹了c#構(gòu)造ColorComboBox的代碼分享,大家參考使用吧

復制代碼 代碼如下:

    class ColorComboBox : ComboBox
    {
        /// <summary>
        /// 當前選中色
        /// </summary>
        public Color SelectedColor
        {
            get { return Color.FromName(this.Text); }
        }
        /// <summary>
        /// 構(gòu)造函數(shù),構(gòu)造顏色下拉列表
        /// </summary>
        public ColorComboBox()
        {
            this.DrawMode = DrawMode.OwnerDrawFixed;
            this.DropDownStyle = ComboBoxStyle.DropDownList;
            this.ItemHeight = 25;

            PropertyInfo[] propInfoList = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);
            foreach (PropertyInfo c in propInfoList)
            {
                this.Items.Add(c.Name);
            }
            this.Text = "Black"; //設置默認色
        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Rectangle rect = e.Bounds;

            if (e.Index >= 0)
            {
                string colorName = this.Items[e.Index].ToString();
                Color c = Color.FromName(colorName);
                using (Brush b = new SolidBrush(c)) //預留下拉項間距
                {
                    e.Graphics.FillRectangle(b, rect.X, rect.Y + 2, rect.Width, rect.Height - 4);
                }
            }
        }

相關文章

最新評論