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

📄 frmtextsettings.cs

📁 Winform_OnlineTraning.rar 培训机构的案例在线培训
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Example1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmTextSettings : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblText;
		private System.Windows.Forms.Button btnFont;
		private System.Windows.Forms.Button btnColor;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnDone;
		private System.Windows.Forms.NumericUpDown updTimes;
		private System.Windows.Forms.Label lblTimes;
		private System.Windows.Forms.TextBox txtTextValue;
		private System.Windows.Forms.FontDialog fdlgFont;
		private System.Windows.Forms.ColorDialog cdlgColor;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmTextSettings()
		{
			//
			// 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()
		{
			System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
			this.txtTextValue = new System.Windows.Forms.TextBox();
			this.lblText = new System.Windows.Forms.Label();
			this.btnFont = new System.Windows.Forms.Button();
			this.btnColor = new System.Windows.Forms.Button();
			this.updTimes = new System.Windows.Forms.NumericUpDown();
			this.btnExit = new System.Windows.Forms.Button();
			this.fdlgFont = new System.Windows.Forms.FontDialog();
			this.cdlgColor = new System.Windows.Forms.ColorDialog();
			this.lblTimes = new System.Windows.Forms.Label();
			this.btnDone = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.updTimes)).BeginInit();
			this.SuspendLayout();
			// 
			// txtTextValue
			// 
			this.txtTextValue.Location = new System.Drawing.Point(10, 43);
			this.txtTextValue.Name = "txtTextValue";
			this.txtTextValue.Size = new System.Drawing.Size(297, 21);
			this.txtTextValue.TabIndex = 0;
			this.txtTextValue.Text = "";
			// 
			// lblText
			// 
			this.lblText.Location = new System.Drawing.Point(19, 17);
			this.lblText.Name = "lblText";
			this.lblText.Size = new System.Drawing.Size(120, 25);
			this.lblText.TabIndex = 1;
			this.lblText.Text = "输入文本:";
			// 
			// btnFont
			// 
			this.btnFont.Location = new System.Drawing.Point(86, 95);
			this.btnFont.Name = "btnFont";
			this.btnFont.Size = new System.Drawing.Size(106, 25);
			this.btnFont.TabIndex = 2;
			this.btnFont.Text = "更改字体(&F)";
			this.btnFont.Click += new System.EventHandler(this.btnFont_Click);
			// 
			// btnColor
			// 
			this.btnColor.Location = new System.Drawing.Point(202, 95);
			this.btnColor.Name = "btnColor";
			this.btnColor.Size = new System.Drawing.Size(105, 25);
			this.btnColor.TabIndex = 3;
			this.btnColor.Text = "更改颜色(&C)";
			this.btnColor.Click += new System.EventHandler(this.btnColor_Click);
			// 
			// updTimes
			// 
			this.updTimes.Location = new System.Drawing.Point(160, 138);
			this.updTimes.Maximum = new System.Decimal(new int[] {
																	 6,
																	 0,
																	 0,
																	 0});
			this.updTimes.Minimum = new System.Decimal(new int[] {
																	 1,
																	 0,
																	 0,
																	 0});
			this.updTimes.Name = "updTimes";
			this.updTimes.Size = new System.Drawing.Size(57, 21);
			this.updTimes.TabIndex = 4;
			this.updTimes.Value = new System.Decimal(new int[] {
																   1,
																   0,
																   0,
																   0});
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(221, 190);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(86, 25);
			this.btnExit.TabIndex = 6;
			this.btnExit.Text = "退出(&E)";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// lblTimes
			// 
			this.lblTimes.Location = new System.Drawing.Point(48, 138);
			this.lblTimes.Name = "lblTimes";
			this.lblTimes.Size = new System.Drawing.Size(110, 26);
			this.lblTimes.TabIndex = 7;
			this.lblTimes.Text = "文本显示次数:";
			// 
			// btnDone
			// 
			this.btnDone.Location = new System.Drawing.Point(115, 190);
			this.btnDone.Name = "btnDone";
			this.btnDone.Size = new System.Drawing.Size(90, 24);
			this.btnDone.TabIndex = 8;
			this.btnDone.Text = "完成(&D)";
			this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
			// 
			// frmTextSettings
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(320, 245);
			this.Controls.Add(this.btnDone);
			this.Controls.Add(this.lblTimes);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.updTimes);
			this.Controls.Add(this.btnColor);
			this.Controls.Add(this.btnFont);
			this.Controls.Add(this.lblText);
			this.Controls.Add(this.txtTextValue);
			this.Name = "frmTextSettings";
			this.Text = ((string)(configurationAppSettings.GetValue("frmClrFnt.Text", typeof(string))));
			((System.ComponentModel.ISupportInitialize)(this.updTimes)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

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

		private void btnFont_Click(object sender, System.EventArgs e)
		{
			fdlgFont.ShowColor = true;
			fdlgFont.Font = txtTextValue.Font;
			fdlgFont.Color = txtTextValue.ForeColor;

			if(fdlgFont.ShowDialog() != DialogResult.Cancel )
			{
				txtTextValue.Font = fdlgFont.Font ;
				txtTextValue.ForeColor = fdlgFont.Color;
			}

		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void btnColor_Click(object sender, System.EventArgs e)
		{
			if(cdlgColor.ShowDialog() == DialogResult.OK)
			{
				txtTextValue.ForeColor  = cdlgColor.Color;
			}

		}

		

		private void btnDone_Click(object sender, System.EventArgs e)
		{
			//increase form size so as to fit in multiple labels
			
            this.Size= new System.Drawing.Size(380,400);

			//create an array of labels
			System.Windows.Forms.Label[] lblText=new Label[Convert.ToInt32(updTimes
				.Value)];
			
            //populate each label of the array
			for(int intCnt=0; intCnt < updTimes.Value;intCnt++)
			{
				lblText[intCnt]=new Label();
				lblText[intCnt].Text = txtTextValue.Text;
				//set the location of the label
				int X = 50;
				int Y = 200+(intCnt*30);
				lblText[intCnt].Font =txtTextValue.Font;
				//change color and font of the label
				lblText[intCnt].ForeColor=txtTextValue.ForeColor; 
				//set the size to be same as the textbox
                lblText[intCnt].Size =  new Size(248, 40);
				lblText[intCnt].Location = new Point(X,Y);
				this.Controls.Add (lblText[intCnt]);
 
			}
		}

	}
}

⌨️ 快捷键说明

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