c#实验三
实验三内容:
自己设计并编写一个 Windows 应用程序,要求用到 TextBox、GroupBox、
RadioButton、CheckBox、ComboBox、ListBox 控件。将程序功能、界面布局和运行结果
的截图与事件代码写在实验报告中。
代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Lab07_2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//index2.jpeg"); if (radioButton2.Checked == true&&radioButton3.Checked==true) { RenNv_Conbobox(); } if (radioButton2.Checked == true && radioButton4.Checked == true) { MoNv_Conbobox(); } if (radioButton2.Checked == true && radioButton5.Checked == true) { XianNv_Conbobox(); } if (radioButton1.Checked == true && radioButton3.Checked == true) { RenNan_Conbobox(); } if (radioButton1.Checked == true && radioButton4.Checked == true) { MoNan_Conbobox(); } if (radioButton1.Checked == true && radioButton5.Checked == true) { XianNan_Conbobox(); } //this.pictureBox1.BackgroundImage = Image.FromFile(@"Resources\logo.jpg"); } /* 添加下拉列表的选项,门派选择列表 */ public void RenNv_Conbobox() { comboBox1.Items.Add("大唐官府");//选择项1 comboBox1.Items.Add("女儿村"); comboBox1.Items.Add("神木林"); comboBox1.Items.Add("天机城"); comboBox1.Items.Add("方寸山"); } public void RenNan_Conbobox() { comboBox1.Items.Add("大唐官府");//选择项1 comboBox1.Items.Add("化生寺"); comboBox1.Items.Add("神木林"); comboBox1.Items.Add("天机城"); comboBox1.Items.Add("方寸山"); } public void MoNv_Conbobox() { comboBox1.Items.Add("阴曹地府");//选择项1 comboBox1.Items.Add("盘丝洞"); comboBox1.Items.Add("魔王寨"); comboBox1.Items.Add("无底洞"); comboBox1.Items.Add("女魃墓"); } public void MoNan_Conbobox() { comboBox1.Items.Add("阴曹地府");//选择项1 comboBox1.Items.Add("狮驼岭"); comboBox1.Items.Add("魔王寨"); comboBox1.Items.Add("无底洞"); comboBox1.Items.Add("女魃墓"); } public void XianNv_Conbobox() { comboBox1.Items.Add("凌波城");//选择项1 comboBox1.Items.Add("普陀山"); comboBox1.Items.Add("天宫"); comboBox1.Items.Add("龙宫"); comboBox1.Items.Add("花果山"); } public void XianNan_Conbobox() { comboBox1.Items.Add("凌波城");//选择项1 comboBox1.Items.Add("五庄观"); comboBox1.Items.Add("天宫"); comboBox1.Items.Add("龙宫"); comboBox1.Items.Add("花果山"); } private void pictureBox1_Click(object sender, EventArgs e) { pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; } private void checkBox1_CheckedChanged(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void groupBox1_Enter(object sender, EventArgs e) { } private void groupBox2_TextChanged(object sender, EventArgs e) { string gender = (this.radioButton1.Checked ? "男" : "女") + "\r\n"; if (gender=="男") { comboBox1.Items.Clear(); RenNan_Conbobox(); } if (gender == "女") { comboBox1.Items.Clear(); RenNv_Conbobox(); } } private void radioButton3_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true && radioButton3.Checked == true) { comboBox1.Items.Clear(); RenNan_Conbobox(); } if (radioButton2.Checked == true && radioButton3.Checked == true) { comboBox1.Items.Clear(); RenNv_Conbobox(); } } private void radioButton4_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true && radioButton4.Checked == true) { comboBox1.Items.Clear(); MoNan_Conbobox(); } if (radioButton2.Checked == true && radioButton4.Checked == true) { comboBox1.Items.Clear(); MoNv_Conbobox(); } } private void radioButton5_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true && radioButton5.Checked == true) { comboBox1.Items.Clear(); XianNan_Conbobox(); } if (radioButton2.Checked == true && radioButton5.Checked == true) { comboBox1.Items.Clear(); XianNv_Conbobox(); } } private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true && radioButton3.Checked == true) { comboBox1.Items.Clear(); RenNan_Conbobox(); } if (radioButton1.Checked == true && radioButton4.Checked == true) { comboBox1.Items.Clear(); MoNan_Conbobox(); } if (radioButton1.Checked == true && radioButton5.Checked == true) { comboBox1.Items.Clear(); XianNan_Conbobox(); } } private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked == true && radioButton3.Checked == true) { comboBox1.Items.Clear(); RenNv_Conbobox(); } if (radioButton2.Checked == true && radioButton4.Checked == true) { comboBox1.Items.Clear(); MoNv_Conbobox(); } if (radioButton2.Checked == true && radioButton5.Checked == true) { comboBox1.Items.Clear(); XianNv_Conbobox(); } } private void button1_Click(object sender, EventArgs e) { String msg = ""; if (textBox1.Text == "" || textBox1 == null) { MessageBox.Show("少侠,请留下您的姓名!\n"); return; } if (comboBox1.Text== "" || comboBox1.Text == null) { MessageBox.Show("少侠,闯荡江湖不易,请选择您的门派!\n"); return; } if (checkBox1.Checked) { msg = msg + "你获得了" + checkBox1.Text+",提升了防御力;"; } if (checkBox2.Checked) { msg = msg + "你获得了" + checkBox2.Text + ",提升了法术伤害;"; } if (checkBox3.Checked) { msg = msg + "获得了" + checkBox3.Text + "提升了一定的速度;"; } if (checkBox4.Checked) { msg = msg + "大唐盛世,神器" + checkBox4.Text + "横空出世,落到了你的手中,提升了大量的物理伤害;"; } if (checkBox5.Checked) { msg = msg + "获得了" + checkBox5.Text + ",眼神涣散,毫无生机的傀儡,可帮助你吸引目标;"; } if (checkBox6.Checked) { msg = msg + "获得了"+ checkBox6.Text + ",这是一种符纸制成的纸人,看起来单薄脆弱,受到伤害时,现身保护主人;"; } if (checkBox7.Checked) { msg = msg + "托塔天王的另一件宝贝" + checkBox7.Text + "又落入你的手中,帮助你积攒愤怒值;"; } if (checkBox8.Checked) { msg = msg + "获得了" + checkBox8.Text+",提升了暴击率;"; } if (checkBox9.Checked) { msg = msg + "获得了" + checkBox9.Text + ",提升了治疗效果。"; } if (msg == "" || msg == null) { MessageBox.Show("少侠,行走江湖不易,请选择几件趁手的法宝吧!\n"); return; } if (listBox1.Text == "" || listBox1.Text == null) { MessageBox.Show("少侠,行走江湖最重要的是人手,请先加入一个帮派吧!\n"); return; } String race = ""; if(radioButton3.Checked){ race="人族"; } else if(radioButton4.Checked){ race="魔族"; } else if(radioButton5.Checked){ race="仙族"; } string gender = ( this.radioButton1.Checked? "男婴" : "女婴" ); if (radioButton2.Checked == true && radioButton3.Checked == true) { pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//feiyannv.jpeg"); //RenNv_Conbobox(); } else if (radioButton2.Checked == true && radioButton4.Checked == true) { // MoNv_Conbobox(); pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//gujingling.jpeg"); } else if (radioButton2.Checked == true && radioButton5.Checked == true) { pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//xuancaie.jpeg"); // XianNv_Conbobox(); } else if (radioButton1.Checked == true && radioButton3.Checked == true) { pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//xiaoyaosheng2.jpeg"); //RenNan_Conbobox(); } else if (radioButton1.Checked == true && radioButton4.Checked == true) { pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//jumowang.jpeg"); // MoNan_Conbobox(); } else if (radioButton1.Checked == true && radioButton5.Checked == true) { pictureBox1.Image = Image.FromFile("C://Users//86157//documents//visual studio 2013//Projects//Lab//Lab07_2//longtaizi.jpeg"); //XianNan_Conbobox(); } string title = " 话说数千年前,蚩尤复活动乱,挑拨仙魔大战,人类为求自保,或投身于两方之一,或自成一伍,一场人、仙、魔三界混战就此拉开帷幕,三界间战火屠天,秩序不复存在。战争终以蚩尤阴谋被揭发为终,人仙魔三族英雄携手将蚩尤打回战神山武神坛下,封印千年。"; string back = "\r\n 岁月滔滔流逝,蚩尤元神被封印之后一念三千,心魔不甘接受战败的宿命,一心想重振旗鼓向世人证明自身的强大无敌,统治一方霸业。当今邪灵欲冲破封印,希望少侠与战神一起保卫梦幻家园。"; textBox2.Text = title+"时至大唐贞观年间。三界大战已平息五百余载,世间重又恢复了安宁与繁荣," + race + gender + textBox1.Text + "诞生,成年后拜入" + comboBox1.Text + "门下,行走江湖中,加入" + listBox1.Text +"帮派,磨练自己,在此期间"+ msg+back; } private void label3_Click(object sender, EventArgs e) { } } }
效果图:
以上内容借鉴梦幻西游内容