标签:style blog http io ar color os 使用 sp
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int year = Convert.ToInt32(comboBox1.Text);//定义一个变量,用来记录当前选择的年份 string strtext = "";//记录所选年份对应的属相; switch(year%12) { case 4: strtext = "鼠"; break; case 5: strtext = "牛"; break; case 6: strtext = "虎"; break; case 7: strtext = "兔"; break; case 0: strtext = "猴"; break; } foreach (System.Windows.Forms.RadioButton rbtn in groupBox1.Controls)//循环遍历groupBox1容器中的单选按钮控件 { if (rbtn.Text == strtext) rbtn.Checked = true; } } private void Form1_Load(object sender, EventArgs e) { for (int i = 1990; i <= 2050; i++) comboBox1.Items.Add(i); comboBox1.Text = DateTime.Now.Year.ToString();//设置下拉列表的默认值为当前年份 } } }
下面这个图里面有窗体里面用到的东西,可以多看下这个文件
下面的与上面的无关:
using System.Windows.Controls;要使用这个命名空间就要加下面选中的那个
标签:style blog http io ar color os 使用 sp
原文地址:http://www.cnblogs.com/leijiangtao/p/4161510.html