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

📄 frmsecond.cs

📁 用C#编的非常好的程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace winappFirst
{
	/// <summary>
	/// frmSecond 的摘要说明。
	/// </summary>
	public class frmSecond : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.GroupBox gbButtonsClick;
		private System.Windows.Forms.Button btnGame;
		private System.Windows.Forms.GroupBox gbxMath;
		private System.Windows.Forms.TextBox txtNum1;
		private System.Windows.Forms.TextBox txtNum2;
		private System.Windows.Forms.Label lblResult;
		private System.Windows.Forms.Label lblEqu;
		private System.Windows.Forms.Label lblOPer;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.RadioButton radioButton1;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.CheckedListBox clb;
		private System.Windows.Forms.Label lbl;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmSecond()
		{
			//
			// 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.btnClose = new System.Windows.Forms.Button();
			this.gbButtonsClick = new System.Windows.Forms.GroupBox();
			this.btnGame = new System.Windows.Forms.Button();
			this.gbxMath = new System.Windows.Forms.GroupBox();
			this.lblOPer = new System.Windows.Forms.Label();
			this.lblEqu = new System.Windows.Forms.Label();
			this.lblResult = new System.Windows.Forms.Label();
			this.txtNum2 = new System.Windows.Forms.TextBox();
			this.txtNum1 = new System.Windows.Forms.TextBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.clb = new System.Windows.Forms.CheckedListBox();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.lbl = new System.Windows.Forms.Label();
			this.gbButtonsClick.SuspendLayout();
			this.gbxMath.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnClose
			// 
			this.btnClose.Location = new System.Drawing.Point(528, 144);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 0;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// gbButtonsClick
			// 
			this.gbButtonsClick.Controls.Add(this.btnGame);
			this.gbButtonsClick.Location = new System.Drawing.Point(16, 16);
			this.gbButtonsClick.Name = "gbButtonsClick";
			this.gbButtonsClick.Size = new System.Drawing.Size(232, 272);
			this.gbButtonsClick.TabIndex = 1;
			this.gbButtonsClick.TabStop = false;
			this.gbButtonsClick.Text = "鼠标触发事件";
			// 
			// btnGame
			// 
			this.btnGame.Location = new System.Drawing.Point(32, 40);
			this.btnGame.Name = "btnGame";
			this.btnGame.Size = new System.Drawing.Size(168, 23);
			this.btnGame.TabIndex = 0;
			this.btnGame.Text = "点击我,你将获得100元";
			this.btnGame.Click += new System.EventHandler(this.btnGame_Click);
			this.btnGame.MouseEnter += new System.EventHandler(this.btnGame_MouseEnter);
			// 
			// gbxMath
			// 
			this.gbxMath.Controls.Add(this.lblOPer);
			this.gbxMath.Controls.Add(this.lblEqu);
			this.gbxMath.Controls.Add(this.lblResult);
			this.gbxMath.Controls.Add(this.txtNum2);
			this.gbxMath.Controls.Add(this.txtNum1);
			this.gbxMath.Location = new System.Drawing.Point(272, 24);
			this.gbxMath.Name = "gbxMath";
			this.gbxMath.Size = new System.Drawing.Size(328, 120);
			this.gbxMath.TabIndex = 2;
			this.gbxMath.TabStop = false;
			this.gbxMath.Text = "除法器";
			// 
			// lblOPer
			// 
			this.lblOPer.Location = new System.Drawing.Point(72, 40);
			this.lblOPer.Name = "lblOPer";
			this.lblOPer.Size = new System.Drawing.Size(24, 23);
			this.lblOPer.TabIndex = 4;
			this.lblOPer.Text = "/";
			// 
			// lblEqu
			// 
			this.lblEqu.Location = new System.Drawing.Point(168, 32);
			this.lblEqu.Name = "lblEqu";
			this.lblEqu.Size = new System.Drawing.Size(32, 23);
			this.lblEqu.TabIndex = 3;
			this.lblEqu.Text = "=";
			this.lblEqu.Click += new System.EventHandler(this.lblEqu_Click);
			// 
			// lblResult
			// 
			this.lblResult.Location = new System.Drawing.Point(216, 32);
			this.lblResult.Name = "lblResult";
			this.lblResult.Size = new System.Drawing.Size(64, 23);
			this.lblResult.TabIndex = 2;
			// 
			// txtNum2
			// 
			this.txtNum2.Location = new System.Drawing.Point(112, 32);
			this.txtNum2.Name = "txtNum2";
			this.txtNum2.Size = new System.Drawing.Size(40, 21);
			this.txtNum2.TabIndex = 1;
			this.txtNum2.Text = "";
			// 
			// txtNum1
			// 
			this.txtNum1.Location = new System.Drawing.Point(16, 32);
			this.txtNum1.Name = "txtNum1";
			this.txtNum1.Size = new System.Drawing.Size(40, 21);
			this.txtNum1.TabIndex = 0;
			this.txtNum1.Text = "";
			this.txtNum1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtNum1_KeyPress);
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(464, 224);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(112, 24);
			this.checkBox1.TabIndex = 3;
			this.checkBox1.Text = "checkBox1";
			// 
			// radioButton1
			// 
			this.radioButton1.Location = new System.Drawing.Point(472, 248);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(152, 24);
			this.radioButton1.TabIndex = 4;
			this.radioButton1.Text = "radioButton1";
			// 
			// radioButton2
			// 
			this.radioButton2.Location = new System.Drawing.Point(480, 288);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(152, 16);
			this.radioButton2.TabIndex = 5;
			this.radioButton2.Text = "radioButton2";
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 12;
			this.listBox1.Location = new System.Drawing.Point(296, 160);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(152, 40);
			this.listBox1.TabIndex = 6;
			// 
			// clb
			// 
			this.clb.Location = new System.Drawing.Point(296, 216);
			this.clb.Name = "clb";
			this.clb.Size = new System.Drawing.Size(144, 52);
			this.clb.TabIndex = 7;
			// 
			// comboBox1
			// 
			this.comboBox1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.comboBox1.Items.AddRange(new object[] {
														   "2",
														   "3",
														   "43",
														   "45",
														   "7",
														   "8"});
			this.comboBox1.Location = new System.Drawing.Point(296, 288);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(121, 20);
			this.comboBox1.Sorted = true;
			this.comboBox1.TabIndex = 8;
			this.comboBox1.Text = "comboBox1";
			// 
			// lbl
			// 
			this.lbl.Location = new System.Drawing.Point(32, 312);
			this.lbl.Name = "lbl";
			this.lbl.Size = new System.Drawing.Size(208, 168);
			this.lbl.TabIndex = 9;
			this.lbl.Paint += new System.Windows.Forms.PaintEventHandler(this.lbl_Paint);
			// 
			// frmSecond
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(696, 485);
			this.Controls.Add(this.lbl);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.clb);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.radioButton2);
			this.Controls.Add(this.radioButton1);
			this.Controls.Add(this.checkBox1);
			this.Controls.Add(this.gbxMath);
			this.Controls.Add(this.gbButtonsClick);
			this.Controls.Add(this.btnClose);
			this.Name = "frmSecond";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "frmSecond";
			this.Load += new System.EventHandler(this.frmSecond_Load);
			this.gbButtonsClick.ResumeLayout(false);
			this.gbxMath.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void btnGame_Click(object sender, System.EventArgs e)
		{
		
			MessageBox.Show("你获得了100元!","恭喜你",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);


		}

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

			if (btnGame.Top<100)
			{

				btnGame.Top=btnGame.Top+100;
			}//if
			else
			{
					btnGame.Top=btnGame.Top-100;

			}//else

		}

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

			float num1,num2,result;
			num1=0;
			num2=1;
			result=0;


            //num1= float.Parse(txtNum1.Text.Trim());
			try
			{
				num1= float.Parse(txtNum1.Text.Trim());
				
			}
			catch (Exception expt)
			{

				MessageBox.Show(expt.Message.ToString());
				//MessageBox.Show("你输入的第一个数据有错误");

				txtNum1.Focus();
				txtNum1.SelectAll();

				return;

			}

		
			
			try
			{
				num2= float.Parse(txtNum2.Text.Trim());
				
			}
			catch 
		{
				MessageBox.Show("你输入的第二个数据有错误");
				txtNum2.Focus();
				txtNum2.SelectAll();
				return;

			}















			result=num1/num2;

			lblResult.Text=result.ToString();




		
		}

		private void txtNum1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
		    // MessageBox.Show(e.KeyChar.ToString()); 
			
			if (e.KeyChar ==13)

				MessageBox.Show("回车");






		}

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

		private void lbl_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
		

			Point   pa= new Point(0,0);
			Point   pb= new Point(0,0);

			pa.X=20;
			pa.Y=20;
			pb.X=80;
			pb.Y=80;

			Point[] pp= new Point[5];
       
			pp[0].X=0;
			pp[0].Y=0;
			pp[1].X=30;
			pp[1].Y=20;
			pp[2].X=50;
			pp[2].Y=70;
			pp[3].X=90;
			pp[3].Y=20;
			pp[4].X=150;
			pp[4].Y=150;




			Graphics   gph= e.Graphics ;
			gph.DrawLine(Pens.Red,pa,pb);
			gph.DrawEllipse(Pens.Blue,50,50,40,80);
			gph.DrawPolygon(Pens.Black,pp);










		}

		
		

		

		
		
	}
}

⌨️ 快捷键说明

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