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

📄 frmfavorites.cs

📁 北大青鸟-Cs学生用书-教师用书实例源代码.rar
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Favorites
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmFavorites : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblName;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.ListBox lstTransport;
		private System.Windows.Forms.ComboBox cboColor;
		private System.Windows.Forms.Label lblMovie;
		private System.Windows.Forms.TextBox txtMovie;
		private System.Windows.Forms.Label lblTransport;
		private System.Windows.Forms.Button btnDone;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
        
		private string color, transport;
		private System.Windows.Forms.Label lblColor;
	
		public frmFavorites()
		{
			//
			// 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.lblName = new System.Windows.Forms.Label();
			this.lblColor = new System.Windows.Forms.Label();
			this.lblTransport = new System.Windows.Forms.Label();
			this.txtName = new System.Windows.Forms.TextBox();
			this.lstTransport = new System.Windows.Forms.ListBox();
			this.cboColor = new System.Windows.Forms.ComboBox();
			this.btnDone = new System.Windows.Forms.Button();
			this.lblMovie = new System.Windows.Forms.Label();
			this.txtMovie = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// lblName
			// 
			this.lblName.Location = new System.Drawing.Point(10, 26);
			this.lblName.Name = "lblName";
			this.lblName.Size = new System.Drawing.Size(86, 25);
			this.lblName.TabIndex = 0;
			this.lblName.Text = "输入姓名: ";
			// 
			// lblColor
			// 
			this.lblColor.Location = new System.Drawing.Point(10, 95);
			this.lblColor.Name = "lblColor";
			this.lblColor.Size = new System.Drawing.Size(144, 25);
			this.lblColor.TabIndex = 1;
			this.lblColor.Text = "输入最喜爱的颜色:";
			// 
			// lblTransport
			// 
			this.lblTransport.Location = new System.Drawing.Point(10, 129);
			this.lblTransport.Name = "lblTransport";
			this.lblTransport.Size = new System.Drawing.Size(172, 17);
			this.lblTransport.TabIndex = 2;
			this.lblTransport.Text = "最喜爱的交通方式:";
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(182, 26);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(125, 21);
			this.txtName.TabIndex = 3;
			this.txtName.Text = "";
			// 
			// lstTransport
			// 
			this.lstTransport.ItemHeight = 12;
			this.lstTransport.Items.AddRange(new object[] {
															  "两轮",
															  "三轮",
															  "地铁"});
			this.lstTransport.Location = new System.Drawing.Point(182, 129);
			this.lstTransport.Name = "lstTransport";
			this.lstTransport.Size = new System.Drawing.Size(125, 28);
			this.lstTransport.TabIndex = 4;
			this.lstTransport.SelectedIndexChanged += new System.EventHandler(this.lstTransport_SelectedIndexChanged);
			// 
			// cboColor
			// 
			this.cboColor.Items.AddRange(new object[] {
														  "红色",
														  "蓝色",
														  "绿色",
														  "橙色",
														  "黄色",
														  "黑色",
														  "白色"});
			this.cboColor.Location = new System.Drawing.Point(182, 95);
			this.cboColor.Name = "cboColor";
			this.cboColor.Size = new System.Drawing.Size(125, 20);
			this.cboColor.TabIndex = 5;
			this.cboColor.SelectedIndexChanged += new System.EventHandler(this.cboColor_SelectedIndexChanged);
			// 
			// btnDone
			// 
			this.btnDone.Location = new System.Drawing.Point(217, 181);
			this.btnDone.Name = "btnDone";
			this.btnDone.Size = new System.Drawing.Size(90, 25);
			this.btnDone.TabIndex = 6;
			this.btnDone.Text = "完成(&D)";
			this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
			// 
			// lblMovie
			// 
			this.lblMovie.Location = new System.Drawing.Point(10, 60);
			this.lblMovie.Name = "lblMovie";
			this.lblMovie.Size = new System.Drawing.Size(172, 25);
			this.lblMovie.TabIndex = 7;
			this.lblMovie.Text = "输入您最喜爱看的电影:";
			// 
			// txtMovie
			// 
			this.txtMovie.Location = new System.Drawing.Point(182, 60);
			this.txtMovie.Name = "txtMovie";
			this.txtMovie.Size = new System.Drawing.Size(125, 21);
			this.txtMovie.TabIndex = 8;
			this.txtMovie.Text = "";
			// 
			// frmFavorites
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(316, 212);
			this.Controls.Add(this.txtMovie);
			this.Controls.Add(this.lblMovie);
			this.Controls.Add(this.btnDone);
			this.Controls.Add(this.cboColor);
			this.Controls.Add(this.lstTransport);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.lblTransport);
			this.Controls.Add(this.lblColor);
			this.Controls.Add(this.lblName);
			this.Name = "frmFavorites";
			this.Text = "我的最爱";
			this.Load += new System.EventHandler(this.frmFavorites_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void btnDone_Click(object sender, System.EventArgs e)
		{
		   MessageBox.Show ("感谢您输入信息!");
			if (color.Equals ("黑色"))
			{
				MessageBox.Show("嗨!我最喜欢的颜色也是黑色");
			}
			if (transport.Equals ("地铁"))
			{
				MessageBox.Show("嗨!我也喜欢乘坐地铁");
			}

		}

		private void lstTransport_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		     transport = lstTransport.SelectedItem.ToString (); 
		}

		private void cboColor_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		     color = cboColor.SelectedItem.ToString (); 
		}

		private void frmFavorites_Load(object sender, System.EventArgs e)
		{
			lstTransport.Text = lstTransport.Items[0].ToString();
            cboColor.Text = cboColor.Items[0].ToString();
        }

	}
}

⌨️ 快捷键说明

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