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

📄 frmsettings.cs

📁 北大青鸟内部资料
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Example
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmSettings : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabPage tabColor;
		private System.Windows.Forms.TabPage tabFont;
		private System.Windows.Forms.ComboBox cboColor;
		private System.Windows.Forms.Label lblRed;
		private System.Windows.Forms.Label lblGreen;
		private System.Windows.Forms.Label lblBlue;
		private System.Windows.Forms.PictureBox picColor;
		private System.Windows.Forms.HScrollBar hsbRed;
		private System.Windows.Forms.HScrollBar hsbGreen;
		private System.Windows.Forms.HScrollBar hsbBlue;
		private System.Windows.Forms.TabControl tabSettings;
		private System.Windows.Forms.Label lblSampleText;
		private System.Windows.Forms.Label lblFont;
		private System.Windows.Forms.ListBox lstFont;
		private System.Windows.Forms.Label lblColor;
		private System.Windows.Forms.RadioButton radLarge;
		private System.Windows.Forms.RadioButton radSmall;

		private bool largeText,smallText;
		private string fontName = "Arial";

		private System.Windows.Forms.Button btnApply;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmSettings()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabSettings = new System.Windows.Forms.TabControl();
			this.tabColor = new System.Windows.Forms.TabPage();
			this.btnApply = new System.Windows.Forms.Button();
			this.lblBlue = new System.Windows.Forms.Label();
			this.lblGreen = new System.Windows.Forms.Label();
			this.lblRed = new System.Windows.Forms.Label();
			this.lblColor = new System.Windows.Forms.Label();
			this.cboColor = new System.Windows.Forms.ComboBox();
			this.picColor = new System.Windows.Forms.PictureBox();
			this.hsbBlue = new System.Windows.Forms.HScrollBar();
			this.hsbGreen = new System.Windows.Forms.HScrollBar();
			this.hsbRed = new System.Windows.Forms.HScrollBar();
			this.tabFont = new System.Windows.Forms.TabPage();
			this.radSmall = new System.Windows.Forms.RadioButton();
			this.radLarge = new System.Windows.Forms.RadioButton();
			this.lblSampleText = new System.Windows.Forms.Label();
			this.lstFont = new System.Windows.Forms.ListBox();
			this.lblFont = new System.Windows.Forms.Label();
			this.tabSettings.SuspendLayout();
			this.tabColor.SuspendLayout();
			this.tabFont.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabSettings
			// 
			this.tabSettings.Controls.Add(this.tabColor);
			this.tabSettings.Controls.Add(this.tabFont);
			this.tabSettings.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabSettings.Location = new System.Drawing.Point(0, 0);
			this.tabSettings.Name = "tabSettings";
			this.tabSettings.SelectedIndex = 0;
			this.tabSettings.Size = new System.Drawing.Size(412, 350);
			this.tabSettings.TabIndex = 0;
			// 
			// tabColor
			// 
			this.tabColor.Controls.Add(this.btnApply);
			this.tabColor.Controls.Add(this.lblBlue);
			this.tabColor.Controls.Add(this.lblGreen);
			this.tabColor.Controls.Add(this.lblRed);
			this.tabColor.Controls.Add(this.lblColor);
			this.tabColor.Controls.Add(this.cboColor);
			this.tabColor.Controls.Add(this.picColor);
			this.tabColor.Controls.Add(this.hsbBlue);
			this.tabColor.Controls.Add(this.hsbGreen);
			this.tabColor.Controls.Add(this.hsbRed);
			this.tabColor.Location = new System.Drawing.Point(4, 21);
			this.tabColor.Name = "tabColor";
			this.tabColor.Size = new System.Drawing.Size(404, 325);
			this.tabColor.TabIndex = 0;
			this.tabColor.Text = "颜色";
			this.tabColor.Click += new System.EventHandler(this.tabColor_Click);
			// 
			// btnApply
			// 
			this.btnApply.Location = new System.Drawing.Point(264, 224);
			this.btnApply.Name = "btnApply";
			this.btnApply.Size = new System.Drawing.Size(90, 24);
			this.btnApply.TabIndex = 9;
			this.btnApply.Text = "立即应用(&A)";
			this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
			// 
			// lblBlue
			// 
			this.lblBlue.Location = new System.Drawing.Point(19, 190);
			this.lblBlue.Name = "lblBlue";
			this.lblBlue.Size = new System.Drawing.Size(58, 24);
			this.lblBlue.TabIndex = 8;
			this.lblBlue.Text = "蓝色:";
			// 
			// lblGreen
			// 
			this.lblGreen.Location = new System.Drawing.Point(19, 146);
			this.lblGreen.Name = "lblGreen";
			this.lblGreen.Size = new System.Drawing.Size(58, 25);
			this.lblGreen.TabIndex = 7;
			this.lblGreen.Text = "绿色:";
			// 
			// lblRed
			// 
			this.lblRed.Location = new System.Drawing.Point(19, 112);
			this.lblRed.Name = "lblRed";
			this.lblRed.Size = new System.Drawing.Size(58, 25);
			this.lblRed.TabIndex = 6;
			this.lblRed.Text = "红色:";
			// 
			// lblColor
			// 
			this.lblColor.Location = new System.Drawing.Point(19, 17);
			this.lblColor.Name = "lblColor";
			this.lblColor.Size = new System.Drawing.Size(87, 25);
			this.lblColor.TabIndex = 5;
			this.lblColor.Text = "选择颜色:";
			// 
			// cboColor
			// 
			this.cboColor.Items.AddRange(new object[] {
														  "Lime",
														  "Yellow",
														  "Red",
														  "SkyBlue",
														  "Magenta"});
			this.cboColor.Location = new System.Drawing.Point(154, 17);
			this.cboColor.Name = "cboColor";
			this.cboColor.Size = new System.Drawing.Size(145, 20);
			this.cboColor.TabIndex = 4;
			this.cboColor.SelectedIndexChanged += new System.EventHandler(this.cboColor_SelectedIndexChanged);
			// 
			// picColor
			// 
			this.picColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.picColor.Location = new System.Drawing.Point(154, 60);
			this.picColor.Name = "picColor";
			this.picColor.Size = new System.Drawing.Size(144, 35);
			this.picColor.TabIndex = 3;
			this.picColor.TabStop = false;
			// 
			// hsbBlue
			// 
			this.hsbBlue.Location = new System.Drawing.Point(106, 190);
			this.hsbBlue.Maximum = 255;
			this.hsbBlue.Name = "hsbBlue";
			this.hsbBlue.Size = new System.Drawing.Size(249, 17);
			this.hsbBlue.TabIndex = 2;
			this.hsbBlue.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbBlue_Scroll);
			// 
			// hsbGreen
			// 
			this.hsbGreen.Location = new System.Drawing.Point(106, 155);
			this.hsbGreen.Maximum = 255;
			this.hsbGreen.Name = "hsbGreen";
			this.hsbGreen.Size = new System.Drawing.Size(249, 17);
			this.hsbGreen.TabIndex = 1;
			this.hsbGreen.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbGreen_Scroll);
			// 
			// hsbRed
			// 
			this.hsbRed.Location = new System.Drawing.Point(106, 112);
			this.hsbRed.Maximum = 255;
			this.hsbRed.Name = "hsbRed";
			this.hsbRed.Size = new System.Drawing.Size(249, 17);
			this.hsbRed.TabIndex = 0;
			this.hsbRed.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbRed_Scroll);
			// 
			// tabFont
			// 
			this.tabFont.Controls.Add(this.radSmall);
			this.tabFont.Controls.Add(this.radLarge);
			this.tabFont.Controls.Add(this.lblSampleText);
			this.tabFont.Controls.Add(this.lstFont);
			this.tabFont.Controls.Add(this.lblFont);
			this.tabFont.Location = new System.Drawing.Point(4, 21);
			this.tabFont.Name = "tabFont";
			this.tabFont.Size = new System.Drawing.Size(404, 325);
			this.tabFont.TabIndex = 1;
			this.tabFont.Text = "字体";
			// 
			// radSmall
			// 
			this.radSmall.Location = new System.Drawing.Point(144, 78);
			this.radSmall.Name = "radSmall";
			this.radSmall.Size = new System.Drawing.Size(106, 25);
			this.radSmall.TabIndex = 4;
			this.radSmall.Text = "缩小文本(&S)";
			this.radSmall.CheckedChanged += new System.EventHandler(this.radSmall_CheckedChanged);
			// 
			// radLarge
			// 
			this.radLarge.Location = new System.Drawing.Point(144, 122);
			this.radLarge.Name = "radLarge";
			this.radLarge.Size = new System.Drawing.Size(106, 26);
			this.radLarge.TabIndex = 3;
			this.radLarge.Text = "放大文本(&L)";
			this.radLarge.CheckedChanged += new System.EventHandler(this.radLarge_CheckedChanged);
			// 
			// lblSampleText
			// 
			this.lblSampleText.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblSampleText.Location = new System.Drawing.Point(19, 224);
			this.lblSampleText.Name = "lblSampleText";
			this.lblSampleText.Size = new System.Drawing.Size(307, 25);
			this.lblSampleText.TabIndex = 2;
			this.lblSampleText.Text = "This is a sample text";
			// 
			// lstFont
			// 
			this.lstFont.AllowDrop = true;
			this.lstFont.ItemHeight = 12;
			this.lstFont.Items.AddRange(new object[] {
														 "Times New Roman",
														 "Arial",
														 "Georgia",
														 "Courier New"});
			this.lstFont.Location = new System.Drawing.Point(144, 26);
			this.lstFont.Name = "lstFont";
			this.lstFont.Size = new System.Drawing.Size(173, 28);
			this.lstFont.TabIndex = 1;
			this.lstFont.SelectedIndexChanged += new System.EventHandler(this.lstFont_SelectedIndexChanged);
			// 
			// lblFont
			// 
			this.lblFont.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblFont.Location = new System.Drawing.Point(19, 34);
			this.lblFont.Name = "lblFont";
			this.lblFont.Size = new System.Drawing.Size(87, 25);
			this.lblFont.TabIndex = 0;
			this.lblFont.Text = "选择字体:";
			// 
			// frmSettings
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(412, 350);
			this.Controls.Add(this.tabSettings);
			this.Name = "frmSettings";
			this.Text = "设置";
			this.Load += new System.EventHandler(this.frmSettings_Load);
			this.tabSettings.ResumeLayout(false);
			this.tabColor.ResumeLayout(false);
			this.tabFont.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmSettings());
		}

		// Apply the cole selected in combobox to the picture box
		private void cboColor_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string colorname = cboColor.SelectedItem.ToString ();
			picColor.BackColor = Color.FromName(colorname);
		}

		// Increase or decrease the gradient of red color
		private void hsbRed_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
		{
			picColor.BackColor = Color.FromArgb(255,hsbRed.Value,hsbGreen.Value,hsbBlue.Value);
		}

		// Increase or decrease the gradient of green color
		private void hsbGreen_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
		{
			picColor.BackColor = Color.FromArgb(255,hsbRed.Value,hsbGreen.Value,hsbBlue.Value);
		}

		// Increase or decrease the gradient of blue color
		private void hsbBlue_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
		{
			picColor.BackColor = Color.FromArgb(255,hsbRed.Value,hsbGreen.Value,hsbBlue.Value);
		}

		// Apply the selected font in Listbox to the sample text
		private void lstFont_SelectedIndexChanged(object sender, System.EventArgs e)
		{
            fontName = lstFont.SelectedItem.ToString();
			if (largeText)
			{
				lblSampleText.Font =  new Font(fontName ,14);
			}
			else
			{
				lblSampleText.Font =  new Font(fontName ,8);
			}
		}

		// Increase the text size if selected
		private void radLarge_CheckedChanged(object sender, System.EventArgs e)
		{
		   largeText = true; 
		   smallText = false;
		   lblSampleText.Font =  new Font(fontName ,14);
		} 

		// Decrease the text size if selected
		private void radSmall_CheckedChanged(object sender, System.EventArgs e)
		{
			smallText = true;
			largeText = false;
			lblSampleText.Font =  new Font(fontName,8);	
		}

		// Apply the color of Picturebox to the selected tabpage and form
		private void btnApply_Click(object sender, System.EventArgs e)
		{
			tabSettings.SelectedTab.BackColor = picColor.BackColor;  
		    this.BackColor = picColor.BackColor;
		}

		private void tabColor_Click(object sender, System.EventArgs e)
		{
			
		}

		private void frmSettings_Load(object sender, System.EventArgs e)
		{
			this.hsbRed.Value = Convert.ToInt32(this.BackColor.R);
			this.hsbBlue.Value = Convert.ToInt32(this.BackColor.G);
			this.hsbGreen.Value = Convert.ToInt32(this.BackColor.G);
			tabSettings.SelectedTab.BackColor = picColor.BackColor;  
			this.BackColor = picColor.BackColor;
		}
	}
}

⌨️ 快捷键说明

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