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. 实例解说AngularJS在自动化测试中的应用

    一.什么是AngularJS ? 1.AngularJS是一组用来开发web页面的框架.模板以及数据绑定和丰富UI的组件: 2.AngularJS提供了一系列健壮的功能,以及将代码隔离成模块的方法: ...

  2. 【题解】危险的工作-C++

    Description 给出一个数字N,N<=11.代表有N个人分担N个危险的工作. 每个人对应每个工作,有个危险值 每个人担任其中一项,问每个人危险值相加,最小值是多少. Input 第一行给 ...

  3. weblogic安装时检查监视器: 必须配置为至少显示 256 种颜色,实际空间未知→失败

    1.首先如果你出现的结果是[未通过],则设置DISPLAY环境变量. 按网上方法:export DISPLAY=:0.0 然后继续安装你的东西……若成功则恭喜你~ 若[失败],按网上方法让你去看日志 ...

  4. 转载《Flex 布局》

    网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂 ...

  5. win10修改桌面图标之间的距离

    操作方法01首先用Win+R组合键打开运行界面,在界面的输入框中输入regedit命令,打开注册表. 02在打开的注册表界面中我们找到HKEY_Current_User下的Control Panel文 ...

  6. 【CYH-01】小奔的国庆练习赛:赛后标程

    前排鸣谢@找寻 大佬 emm-由于头一次举办公开赛所以--准备不是很充分,所以说题解也没有备好,在这里表示歉意. 欢迎大家来发布题解,在此我们可以提供AC代码,供大家参考. T1 解析:这一题可能栈溢 ...

  7. 【Android UI】顶部or底部菜单的循环滑动效果一

    实现了分页的滑动效果,做的demo流畅运行 注:貌似支持的样式(控件)有一定的限制,我试过短信的listview页面,暂无法实现滑动效果 java文件:MainActivity.java.Activi ...

  8. 个人永久性免费-Excel催化剂功能第67波-父子结构表转换添加辅助信息之子父关系篇

    Excel作为一款数据领域的万物互联工具,连接一切外部的多种多样的数据源.将数据带到Excel的环境中,再进行数据处理.转换.统计分析等工作,是众多表哥表姐们每天都在经历的事情.能最快速将其他来源数据 ...

  9. Git储藏和引用日志

    在日常工作中,当要经常停下手头的工作区修复临时的BUG,紧急处理来自同事或者经理的请求,但是又不能将手头的工作进行提交的时候.那么Git储藏功能(stash)就起到作用了. 储藏可以捕获我们的工作区状 ...

  10. md文档的书写《二》

    对<md文档的书写一>的补充和部分归总 我使用的是Typora,快捷键可能有些片面,没有特殊说明,下文所有快捷键都是Typora编辑器下支持的快捷键,望知晓. 关于标题的书写补充 除了 ( ...