combobox 添加颜色下拉框

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 继承) 返回表示当前 ObjectString

受保护的方法

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

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

MemberwiseClone(从 Object 继承)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章