using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data; namespace Combox
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(, );
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(, );
this.comboBox1.TabIndex = ;
this.comboBox1.SelectedIndexChanged = new System.EventHandler(this.comboBox1_SelectedIndexChanged);
this.comboBox1.MeasureItem = new System.Windows.Forms.MeasureItemEventHandler(this.comboBox1_MeasureItem);
this.comboBox1.DrawItem = new System.Windows.Forms.DrawItemEventHandler(this.comboBox1_DrawItem);
//
// label1
//
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "请在组合框中选择颜色值:";
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.panel1.Location = new System.Drawing.Point(, );
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(, );
this.panel1.TabIndex = ;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(, );
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.panel1);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "演示制作带图形的组合框";
this.Load = new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} 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(Brushes.White);
this.comboBox1.Items.Add(Brushes.Yellow);
} private void comboBox1_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
{//设置列表项宽
e.ItemHeight=this.comboBox1.ItemHeight-;
} private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{//绘制列表项 ComboBox MyCombox=(ComboBox)sender;
if(e.Index==-)
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(,);
MyRect.Width=;
MyRect.Height-=;
g.DrawRectangle(new Pen(e.ForeColor),MyRect);
//获取选定颜色的相应画刷对象,并填充预览框
MyRect.Offset(,);
MyRect.Width-=;
MyRect.Height-=;
g.FillRectangle(MyBrush,MyRect);
//绘制选定颜色的名称
g.DrawString(MyBrush.Color.Name.ToString(),Font,new SolidBrush(e.ForeColor),e.Bounds.X ,e.Bounds.Y );
} private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{//显示选择的颜色
if(this.comboBox1.SelectedIndex>=)
{
SolidBrush MyBrush=(SolidBrush)(this.comboBox1.SelectedItem);
this.panel1.BackColor=MyBrush.Color;
}
}
}
}

颜色下拉菜单(combox)的更多相关文章

  1. jQuery 小特效【文本框折叠隐藏,展开显示】【下拉菜单】【颜色渐变】【弹窗+遮罩】

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  2. vue实现隔行换色,下拉菜单控制隔行换色的颜色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. IOS第二天-新浪微博 - 添加搜索框,弹出下拉菜单 ,代理的使用 ,HWTabBar.h(自定义TabBar)

    ********HWDiscoverViewController.m(发现) - (void)viewDidLoad { [super viewDidLoad]; // 创建搜索框对象 HWSearc ...

  4. Bootstrap之样式风格与下拉菜单

    背景颜色 bg-primary 字体颜色 text-primary 文字居中 text-center 按钮 btn btn-primary btn-default默认 btn-link链接 按钮大小 ...

  5. SJPullDownMenu下拉菜单框架使用

    SJPullDownMenu 快速集成类似淘宝筛选下拉菜单 如果页面显示不全等问题请转至:http://www.jianshu.com/p/d07c6393830c 查看使用 Getting Star ...

  6. Bootstrap框架(基础篇)之按钮,网格,导航栏,下拉菜单

    一,按钮 注意:虽然在Bootstrap框架中使用任何标签元素都可以实现按钮风格,但个人并不建议这样使用,为了避免浏览器兼容性问题,个人强烈建议使用button或a标签来制作按钮. 框架中提供了基础按 ...

  7. Dwz下拉菜单的二级联动

    在DWZ文档中对组合框combox的是这样描述的: 在传统的select 用class 定义:class=”combox”, html 扩展:保留原有属性name,  增加了属性:ref. ref 属 ...

  8. 形行色色的下拉菜单(HTML/CSS JS方法 jQuery方法实现)

    HTML/CSS方法实现下拉菜单来源:慕课网<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...

  9. excel设置下拉菜单,并且不同值会显示不同颜色

    工作中常常要用的excel,每次都会有新的需求,然后不会,然后百度,然后过段时间可能就又忘了,于是就想说,自己记录下来~~~因为自己用的都是2010,其实哪个版本都差不多,都是应该可以找到相应的按钮滴 ...

随机推荐

  1. eclipse+MyEclipse+WebLogic开发简单的EJB

    转载自http://blog.sina.com.cn/s/blog_678530f60100hxaf.html 说是转载,其实这是我个人在几年前新浪博客上发表的文章. 帮导师搞了一周的EJB,总算初步 ...

  2. 用Python玩数据-笔记整理-第一章-练习与测试

    编程题: 简单的输入输出:编程实现输入姓.名的提示语并接受用户输入,并单独显示姓.名和全名,执行效果如下所示: Input your surname:ZHANG Input your firstnam ...

  3. Java调用方法参数究竟是传值还是传址?

    之前阅读<Head First Java>的时候,记得里面有提到过,Java在调用方法,传递参数的时候,采用的是pass-by-copy的方法,传递一份内容的拷贝,即传值.举一个最简单的例 ...

  4. Spring 注解编程之 AnnotationMetadata

    在上篇文章 Spring 注解编程之模式注解 中我们讲到 Spring 模式注解底层原理,依靠 AnnotationMetadata 接口判断是否存在指定元注解. 这篇文章我们主要深入 Annotat ...

  5. 摄像头驱动的使能配置、V4L2编程接口的设计应用

    摄像头采集子系统 一.摄像头驱动的使能配置 摄像头软件驱动构架 摄像头采集系统由上图所示,硬件(摄像头) -> 驱动(Linux内核配置中,选择支持V4L2的驱动选项) -> V4L2接口 ...

  6. http://www.jianshu.com/p/2dd54ec0bb43 程序员纪录片

    http://www.jianshu.com/p/2dd54ec0bb43 程序员纪录片

  7. 个人永久性免费-Excel催化剂功能第85波-灵活便捷的批量发送短信功能(使用腾讯云接口)

    微信时代的今天,短信一样不可缺席,大系统都有集成短信接口.若只是临时用一下,若能够直接在Excel上加工好内容就可以直接发送,这些假设在此篇批量群发短信功能中都为大家带来完美答案. 业务场景 不多说, ...

  8. 将web工程署到Linux简单实现

    1,将数据库文件导出并导入到Linux下的数据库中 2,将数据库连接池的连接IP改为Linux所在服务器的 3,将工程文件以war包形式导出 4,利用secureCRT,Xshell等工具远程连接Li ...

  9. Python学习6——再谈抽象(面对对象编程)

    1.对象魔法 在面对对象编程中,术语对象大致意味着一系列数据(属性)以及一套访问和操作这些数据的方法. 使用对象而非全局变量以及函数的原因有多个,而最重要的好处不过以下几点: 多态:可对不同类型的对象 ...

  10. java练习---9

    //程序员:罗元昊 2017.10.22 package cn.lyh; import com.rupeng.game.GameCore; public class L implements Runn ...