combobox 添加颜色下拉框

来源:互联网 发布:故宫淘宝为什么红 编辑:程序博客网 时间:2024/05/17 09:12
combobox 添加颜色下拉框
2007-05-18 10:57

其实就是baidu一些常用的

代码如下

private void Form1_Load(object sender, System.EventArgs e)
   {
   // this.comboBox1.DisplayMember="Color";
    this.comboBox1.Items.Add(Brushes.Cyan);
    this.comboBox1.Items.Add(Brushes.DarkSalmon);
    this.comboBox1.Items.Add(Brushes.Gray);
    this.comboBox1.Items.Add(Brushes.Green);
    this.comboBox1.Items.Add(Brushes.AliceBlue);
    this.comboBox1.Items.Add(Brushes.Black);
    this.comboBox1.Items.Add(Brushes.Blue);
    this.comboBox1.Items.Add(Brushes.Chocolate);
    this.comboBox1.Items.Add(Brushes.Pink);
    this.comboBox1.Items.Add(Brushes.Red);
    this.comboBox1.Items.Add(Brushes.LightBlue);
    this.comboBox1.Items.Add(Brushes.Brown);
    this.comboBox1.Items.Add(Brushes.DodgerBlue);
    this.comboBox1.Items.Add(Brushes.MediumPurple);
    this.comboBox1.Items.Add(Color.White);
    this.comboBox1.Items.Add(Brushes.Yellow);   
   }

   private void comboBox1_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
   {//ノ靹テチミア榘錞・
    e.ItemHeight=this.comboBox1.ItemHeight-2;   
   }

   private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
   {//サ贍ニチミア榘・

    ComboBox MyCombox=(ComboBox)sender;
    if(e.Index==-1)
     return;
    if(sender==null)
     return;
    SolidBrush MyBrush=(SolidBrush)MyCombox.Items[e.Index];
    Graphics g=e.Graphics;
    //ネ郢鋐ムセュス ミム。ヤ ャヤ 贍ニユネキオトアウセームユノォコヘセロシッソ・
    e.DrawBackground();
    e.DrawFocusRectangle();
    //サ贍ニムユノォオトヤ、タタソ・
    Rectangle MyRect=e.Bounds;
    MyRect.Offset(2,2);
    MyRect.Width=50;
    MyRect.Height-=4;
    g.DrawRectangle(new Pen(e.ForeColor),MyRect);
    //サ 。ム。カィムユノォオトマ獗ヲサュヒ「カヤマ ャイ「フ鋧蕚、タタソ・
    MyRect.Offset(1,1);
    MyRect.Width-=2;
    MyRect.Height-=2;
    g.FillRectangle(MyBrush,MyRect);
    //サ贍ニム。カィムユノォオトテ﨤ニ
    g.DrawString(MyBrush.Color.Name.ToString(),Font,new SolidBrush(e.ForeColor),e.Bounds.X+60,e.Bounds.Y+1);
   }

   private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
   {//マヤハセム。ヤ トムユノォ
    if(this.comboBox1.SelectedIndex>=0)
    {
     SolidBrush MyBrush=(SolidBrush)(this.comboBox1.SelectedItem);
     this.panel1.BackColor=MyBrush.Color;    
    }   
   }
}

Brushes类

所有标准颜色的画笔

DrawItemEventArgs 成员

公共构造函数

公共构造函数DrawItemEventArgs 构造函数已重载。初始化 DrawItemEventArgs 类的新实例。

公共属性

公共属性BackColor获取所绘制的项的背景色。公共属性Bounds获取表示所绘制项的边界的矩形。公共属性Font获取分配给所绘制项的字体。公共属性ForeColor获取所绘制项的前景色。公共属性Graphics获取要在其上绘制项的图形表面。公共属性Index获取所绘制项的索引值。公共属性State获取所绘制项的状态。

公共方法

公共方法DrawBackground在 DrawItemEventArgs 构造函数指定的边界范围内用适当的颜色绘制背景。公共方法DrawFocusRectangle在 DrawItemEventArgs 构造函数指定的边界范围内绘制聚焦框。公共方法Equals(从 Object 继承)已重载。确定两个 Object 实例是否相等。公共方法GetHashCode(从 Object 继承)用作特定类型的哈希函数,适合在哈希算法和数据结构(如哈希表)中使用。公共方法GetType(从 Object 继承)获取当前实例的 Type。公共方法ToString(从 Object 继承)返回表示当前 Object 的 String。

受保护的方法

受保护的方法Finalize(从 Object 继承)已重写。允许 Object 在“垃圾回收”回收 Object 之前尝试释放资源并执行其他清理操作。

在 C# 和 C++ 中,使用析构函数语法来表示终结程序。

受保护的方法MemberwiseClone(从 Object 继承)
原创粉丝点击