⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorpicker.cs

📁 一个可以定时开关机提醒的界面语音时钟程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace MyClock
{
	/// <summary>
	/// ColorPicker 的摘要说明。
	/// </summary>
	public class ColorPicker : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox ColorList;



		private string []data;
		private Color []color;
		public string SelectedColor;
		private System.Windows.Forms.Button BtnOk;
		private System.Windows.Forms.Button BtnCancle;
		private System.Windows.Forms.Label label1;


		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ColorPicker()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//


			data= new String[10]{"Red","Blue","Green","Yellow","Black",
									"Aqua","Brown","Cyan","Gray","Pink"};
			ColorList.DataSource= data;

			color= new Color[10]{Color.Red,Color.Blue,Color.Green,Color.Yellow,Color.Black,
									Color.Aqua,Color.Brown,Color.Cyan,Color.Gray, Color.Pink};
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.ColorList = new System.Windows.Forms.ListBox();
			this.BtnOk = new System.Windows.Forms.Button();
			this.BtnCancle = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// ColorList
			// 
			this.ColorList.ItemHeight = 12;
			this.ColorList.Location = new System.Drawing.Point(8, 8);
			this.ColorList.Name = "ColorList";
			this.ColorList.Size = new System.Drawing.Size(96, 172);
			this.ColorList.TabIndex = 0;
			this.ColorList.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.ColorList_MeasureItem);
			this.ColorList.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ColorList_DrawItem);
			this.ColorList.SelectedIndexChanged += new System.EventHandler(this.ColorList_SelectedIndexChanged);
			// 
			// BtnOk
			// 
			this.BtnOk.Location = new System.Drawing.Point(112, 128);
			this.BtnOk.Name = "BtnOk";
			this.BtnOk.TabIndex = 1;
			this.BtnOk.Text = "确定";
			this.BtnOk.Click += new System.EventHandler(this.BtnOk_Click);
			// 
			// BtnCancle
			// 
			this.BtnCancle.Location = new System.Drawing.Point(112, 160);
			this.BtnCancle.Name = "BtnCancle";
			this.BtnCancle.TabIndex = 2;
			this.BtnCancle.Text = "取消";
			this.BtnCancle.Click += new System.EventHandler(this.BtnCancle_Click);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Black;
			this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.label1.Location = new System.Drawing.Point(112, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(75, 48);
			this.label1.TabIndex = 3;
			// 
			// ColorPicker
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(200, 197);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label1,
																		  this.BtnCancle,
																		  this.BtnOk,
																		  this.ColorList});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "ColorPicker";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "颜色选择";
			this.TopMost = true;
			this.ResumeLayout(false);

		}
		#endregion

		private void ColorList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
		{
			e.DrawBackground();
			e.DrawFocusRectangle();
			e.Graphics.DrawString(data[e.Index],new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold),new SolidBrush(color[e.Index]),e.Bounds);
		}

		private void ColorList_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
		{
			e.ItemHeight= 22;
		}

		private void ColorList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.SelectedColor = this.ColorList .SelectedItem .ToString ();
			this.label1 .BackColor = Color.FromName (SelectedColor);
		}

		private void BtnCancle_Click(object sender, System.EventArgs e)
		{
			this.SelectedColor = "" ;
			this.Close ();
		}

		private void BtnOk_Click(object sender, System.EventArgs e)
		{
			this.Close ();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -