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

📄 sample17.cs

📁 C#函数手册
💻 CS
字号:
namespace apiBook
{
	using System;
	using System.Drawing;
	using System.Collections;
	using System.ComponentModel;
	using System.Windows.Forms;
	using System.Data;
	using System.IO ;
	public class TestCombox : Form 
	{
		private System.Windows.Forms.Button addButton;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button addGrandButton;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Button showSelectedButton;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button findButton;
		private System.Windows.Forms.Label label1;
		public TestCombox() 
		{
			this.InitializeComponent();
		}
		[System.STAThreadAttribute()]
		public static void Main() 
		{
			Application.Run(new TestCombox());
		}        
		private void InitializeComponent() 
		{
			this.addButton = new Button();
			this.textBox2 = new TextBox();
			this.addGrandButton = new Button();
			this.comboBox1 = new ComboBox();
			this.showSelectedButton = new Button();
			this.textBox1 = new TextBox();
			this.findButton = new Button();
			this.label1 = new Label();
			this.addButton.Location = new  Point(150, 32);
			this.addButton.Size = new Size(80, 24);
			this.addButton.TabIndex = 1;
			this.addButton.Text = "添加水果类型";
			this.addButton.Click+=new EventHandler(this.addButton_Click);
			this.textBox2.Location = new Point(8, 64);
			this.textBox2.Size = new Size(100, 20);
			this.textBox2.TabIndex = 7;
			this.textBox2.Text = "";			
			this.comboBox1.Anchor = ((AnchorStyles.Bottom | 
				AnchorStyles.Left) | AnchorStyles.Right);
			this.comboBox1.DropDownWidth = 200;
			this.comboBox1.Items.AddRange(new object[] {"Apple", 
														   "Orange", "Watermelon", "Banana","Grape","Pear"});
			this.comboBox1.Location = new Point(8, 140);
			this.comboBox1.Size = new  Size(220, 21);
			this.comboBox1.TabIndex = 7;
			this.showSelectedButton.Location = new  Point(8, 100);
			this.showSelectedButton.Size = new  Size(200, 24);
			this.showSelectedButton.TabIndex = 4;
			this.showSelectedButton.Text = "选择的水果类型";
	 
			this.showSelectedButton.Click+=
				new EventHandler(this.showSelectedButton_Click);
			this.textBox1.Location = new  Point(8, 32);
			this.textBox1.Size = new  Size(100, 20);
			this.textBox1.TabIndex = 5;
			this.textBox1.Text = "";
			this.findButton.Location = new  Point(150, 64);
			this.findButton.Size = new Size(80, 24);
			this.findButton.TabIndex = 3;
			this.findButton.Text = "查找水果类型";
			this.findButton.Click+=
				new EventHandler(this.findButton_Click);
			this.label1.Location = new  Point(8, 224);
			this.label1.Size = new Size(144, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Test ComboBox";
			this.AutoScaleBaseSize = new  Size(5, 13);
			this.ClientSize = new Size(250, 180);
			this.Controls.AddRange(
				new  Control[] {this.comboBox1, this.textBox2,this.textBox1, this.showSelectedButton,this.findButton,this.addButton, this.label1});
			this.Text = "水果种类收集器";
		}
		private void addButton_Click(object sender, EventArgs e) 
		{
			comboBox1.Items.Add(textBox1.Text);
		}
		private void findButton_Click(object sender,EventArgs e) 
		{
			int index = comboBox1.FindString (textBox2.Text);
			comboBox1.SelectedIndex = index;
		}
		private void showSelectedButton_Click(object sender, EventArgs e) 
		{
			int selectedIndex = comboBox1.SelectedIndex;
			Object selectedItem = comboBox1.SelectedItem;
			MessageBox.Show("选择了水果: " + selectedItem.ToString() 
				+ "。\n" +"位置: " + selectedIndex.ToString());
		}
	}
}

⌨️ 快捷键说明

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