星空网 > 软件开发 > ASP.net

图片切换(手动切换,imagelist的单独使用)

  1. //当前图片的索引
  2. private int currIndex = 0;
  3. //判断上一个按钮和下一个按钮是否可用
  4. private void SetEabled()
  5.  {
  6.     //如果当前显示的是第一张图片,则“上一张”按钮不可用
  7.     //判断是否为第一张
  8.     if (currIndex > 0)
  9.         //不是第一张,“上一张”按钮可用
  10.          this.button1.Enabled = true;
  11.     else
  12.          this.button1.Enabled = false;
  13.          //如果当前显示的是最后一张张图片,则“下一张”按钮不可用
  14.          //判断是否为最后一张
  15.     if (currIndex == this.imageList1.Images.Count - 1)
  16.            //不是第一张,“下一张”按钮可用
  17.            this.button2.Enabled = false;
  18.     else
  19.            this.button2.Enabled = true;
  20.  }
  21. //窗体添加窗体加载(Load)事件
  22. private void Form2_Load(object sender, EventArgs e)
  23.  {
  24.       //进入窗体,显示第一张图片
  25.        this.pictureBox1.Image = this.imageList1.Images[0];
  26.       //“上一张”按钮可用
  27.       this.button1.Enabled = false;
  28.  }
  29. //上一张按钮添加单击事件
  30. private void button1_Click(object sender, EventArgs e)
  31.   {
  32.      //当前图片索引减一
  33.      currIndex--;
  34.      //设置按钮是否可用
  35.      SetEabled();
  36.      //将当前图片显示到图片框中
  37.      this.pictureBox1.Image = this.imageList1.Images[currIndex];
  38.   }
  39. //下一张按钮添加单击事件
  40. private void button2_Click(object sender, EventArgs e)
  41.   {
  42.         //当前图片索引加一
  43.         currIndex++;
  44.         //设置按钮是否可用
  45.         SetEabled();
  46.         //将当前图片显示到图片框中
  47.         this.pictureBox1.Image = this.imageList1.Images[currIndex];
  48.      }



原标题:图片切换(手动切换,imagelist的单独使用)

关键词:图片

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流