国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

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

2020-01-24 03:00:47
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

    class ColorComboBox : ComboBox
    {
        /// <summary>
        /// 當(dāng)前選中色
        /// </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"; //設(shè)置默認(rèn)色
        }

        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)) //預(yù)留下拉項(xiàng)間距
                {
                    e.Graphics.FillRectangle(b, rect.X, rect.Y + 2, rect.Width, rect.Height - 4);
                }
            }
        }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 克拉玛依市| 施甸县| 枣阳市| 长沙市| 迁安市| 库伦旗| 凤阳县| 嘉义市| 平和县| 潢川县| 融水| 古丈县| 惠安县| 茂名市| 九寨沟县| 义乌市| 河曲县| 广饶县| 汶上县| 平塘县| 浠水县| 静宁县| 岱山县| 安远县| 安龙县| 兴化市| 电白县| 余庆县| 长乐市| 三穗县| 浮梁县| 合肥市| 江门市| 许昌市| 新源县| 双柏县| 全州县| 高雄市| 勐海县| 体育| 汝州市|