今天由于是周六,所以就没讲课啦,于是我就仔细看啦几道还没掌握的题,然后总结啦一下。
一.三级联动
像这个三级联动吧,感觉在做网站时间肯定会用到啦,但是那时间肯定不会是这样子做的啦,不可能把所有的省市区区什么的全部给添加到一个数组里面排列出来,所以学习这个从基础学起啦,先培养下思想,列举出来几个省市区然后列举出来,下面就简单列举下河南,河北和西藏这三个省的市和区,如下所示:
public partial class Form1 : Form { string[] pri = { "请选择省份","河南", "河北", "西藏" }; string[] henancity = { "请选择城市", "郑州", "洛阳", "新乡" }; string[] hebeicity = { "请选择城市", "北京", "石家庄", "张家口", "邯郸" }; string[] xizangcity = { "请选择城市", "拉萨" }; string[] zhengzhouarea = { "请选择区域", "金水区", "中原区", "二七区", "经开区", "管城区" }; string[] luoyangarea = { "请选择区域", "洛龙区", "吉利区", "老城区", "西工区", "涧西区" }; string[] xinxiangarea = { "请选择区域", "红旗区", "牧野区", "卫滨区", "凤泉区" }; string[] beijingarea = { "请选择区域", "海淀区", "朝阳区", "东城区", "西城区", "丰台区" }; string[] shijiazhuangarea = { "请选择区域", "请选择区域", "桥东区", "桥西区", "裕华区", "新华区", "长安区" }; string[] zhangjiakouarea = { "请选择区域", "高新区", "塞北区", "察北区", "桥东区", "桥西区" }; string[] handanarea = { "请选择区域", "丛台区", "邯山区", "复兴区", "峰峰矿区" }; string[] lasaarea = { "请选择区域", "日喀则地区", "昌都地区", "林芝地区", "山南地区", "那曲地区", "阿里地区" }; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.conpri.Items.AddRange(pri); this.conpri.SelectedIndex = 0; } private void conpri_SelectedIndexChanged(object sender, EventArgs e) { string value =this.conpri.SelectedItem.ToString(); switch (value) { case "河南": this.comcity.Items.Clear(); this.comcity.Items.AddRange(henancity); this.comcity.SelectedIndex = 0; break; case "河北": this.comcity.Items.Clear(); this.comcity.Items.AddRange(hebeicity); this.comcity.SelectedIndex = 0; break; case "西藏": this.comcity.Items.Clear(); this.comcity.Items.AddRange(xizangcity); this.comcity.SelectedIndex = 0; break; default: break; } } private void comcity_SelectedIndexChanged(object sender, EventArgs e) { //int index = this.comcity.SelectedIndex; #region MyRegion object text = this.comcity.SelectedItem; string priv =this.conpri.SelectedItem.ToString(); switch (priv) { case "河南": if (text.Equals("郑州")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(zhengzhouarea); this.comarea.SelectedIndex = 0; } else if (text.Equals("洛阳")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(luoyangarea); this.comarea.SelectedIndex = 0; } else if (text.Equals("新乡")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(xinxiangarea); this.comarea.SelectedIndex = 0; } break; case "河北": if (text.Equals( "北京")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(beijingarea); this.comarea.SelectedIndex = 0; } else if (text.Equals("石家庄")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(shijiazhuangarea); this.comarea.SelectedIndex = 0; } else if (text.Equals("张家口")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(zhangjiakouarea); this.comarea.SelectedIndex = 0; } else if (text.Equals("邯郸")) { this.comarea.Items.Clear(); this.comarea.Items.AddRange(handanarea); this.comarea.SelectedIndex = 0; } break; case "西藏": this.comarea.Items.Clear(); this.comarea.Items.AddRange(lasaarea); this.comarea.SelectedIndex = 0; break; default: break; #endregion } } }
二.图片的翻页
由于在用文件这个方法时,感觉很是陌生吧,所以感觉这个也是蛮重要的啦,但是总感觉程序看起来也是蛮简单的,总是让自己写起来却不能独立完成啦,下面就把这个的思想在总结一下,希望下次我再用到这个方法啦能够和他成为好朋友似的,顺利的完成啦,下面就以图片的翻页为例写个程序吧,如下代码所示:
public partial class btnnext : Form { public btnnext() { InitializeComponent(); } private void btnnext_Load(object sender, EventArgs e) { string[] path = Directory.GetFiles(@"I:练习项目11月27日 1radiocheckboximg"); //启动项目时间可以加载一张图片。 this.pictureBox1.Image = Image.FromFile(path[0]); //这里设置为默认的第一张图片 } int i = 0; private void btnone_Click(object sender, EventArgs e) { string[] path = Directory.GetFiles(@"I:练习项目11月27日 1radiocheckboximg"); //获取图片索引 if (i == 0) { this.pictureBox1.Image = Image.FromFile(path[path.Length - 1]); i = path.Length - 1; } else { i--; this.pictureBox1.Image = Image.FromFile(path[i]); } } private void button2_Click(object sender, EventArgs e) { string[] path = Directory.GetFiles(@"I:练习项目11月27日 1radiocheckboximg"); //获取图片索引存放在数组里面 //i++; //this.pictureBox1.Image = Image.FromFile(path[0]); 本应该这样,但是由于在最后一张图片时间下一张要回到第一张来, //所以判断一下是否为第一张然后在输出。 if (i.Equals(path.Length-1)) { i = 0; this.pictureBox1.Image = Image.FromFile(path[0]); //当为第一张时间,点击按钮,则应该为上一张, //而上一张为最后一张,即从索引值获取最后一张照片 } else { i++; this.pictureBox1.Image = Image.FromFile(path[i]); } } }
三.用Timer控件显示图片
说起来Timer控件,感觉好玩,图片可以自动播放,只需要改变一下Interval,设置其自动播放的时间,然后把Enabled设置为true,在这里一般默认为false,设置后后即可,在程序中设置图片可以是顺序显示也可以是倒序显示额,具体的和上面上一张和下一张图片的显示类似,实现其代码如下:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] path = Directory.GetFiles(@"I:练习项目11月27日 1radiocheckboximg"); private void Form1_Load(object sender, EventArgs e) { this.pictureBox1.Image = Image.FromFile(path[0]); } int i = 0; private void timer1_Tick(object sender, EventArgs e) { #region 图片倒叙显示 //if (i.Equals(0)) //{ // this.pictureBox1.Image = Image.FromFile(path[path.Length - 1]); // i = path.Length - 1; //} //else //{ // this.pictureBox1.Image = Image.FromFile(path[i - 1]); // i--; //} #endregion #region 图片顺序排列 i++; if (i.Equals(path.Length)) { //i = 0; this.pictureBox1.Image = Image.FromFile(path[0]); } else { this.pictureBox1.Image = Image.FromFile(path[i]); } #endregion } }
好啦,感觉今天只是把前几天学习的在练习下的啦,重复学习可能有新的收获额,我还要继续努力啦,感觉熟练才是最根本的。