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获取所绘制项的状态。
公共方法
公共方法DrawBackgroundDrawItemEventArgs 构造函数指定的边界范围内用适当的颜色绘制背景。
公共方法DrawFocusRectangleDrawItemEventArgs 构造函数指定的边界范围内绘制聚焦框。
公共方法Equals(从 Object 继承)已重载。确定两个 Object 实例是否相等。
公共方法GetHashCode(从 Object 继承)用作特定类型的哈希函数,适合在哈希算法和数据结构(如哈希表)中使用。
公共方法GetType(从 Object 继承)获取当前实例的 Type
公共方法ToString(从 Object 继承)返回表示当前 ObjectString
受保护的方法
受保护的方法Finalize(从 Object 继承)已重写。允许 Object 在“垃圾回收”回收 Object 之前尝试释放资源并执行其他清理操作。

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

受保护的方法MemberwiseClone(从 Object 继承)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值