码迷,mamicode.com
首页 > Windows程序 > 详细

c#图片浏览

时间:2016-01-09 18:28:31      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace Experiment1201
{
    public partial class Form1 : Form
    {
        int iWideth=0;
        FolderBrowserDialog browser = new FolderBrowserDialog();
        string mypath;
       
        public Form1()
        {
            InitializeComponent();
        }
       
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            picPicture.Load(@mypath + @"\" + listFile.SelectedItem);
            label1.Text = "第" + (1 + listFile.SelectedIndex).ToString() + "张 共" + listFile.Items.Count.ToString() + "张";
        }

        private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //添加代码
          
           
                  if (e.KeyChar == 32)
                {
                    if (listFile.Items.Count > 0) //如果listBox本身没有数据,则不增加listBox的索引
                    {
                        if (listFile.SelectedIndex >= listFile.Items.Count - 1) //listBox的索引不能超过listBox本身的图片数-1
                            listFile.SelectedIndex = 0;
                        else
                            listFile.SelectedIndex++;
                    }

                    if (listFile.Items.Count > 0) //如果listBox本身没有数据,则不运行以下内容
                    {
                        label1.Text = "第" + (1 + listFile.SelectedIndex).ToString() + "张 共" + listFile.Items.Count.ToString() + "张";
                        picPicture.Load(@mypath + @"\" + listFile.SelectedItem);
                    }
                }
           
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            //添加代码
            listFile.Items.Clear();
            browser.SelectedPath = @"F:\c#\solution11\图片";
            DialogResult dr = browser.ShowDialog();
            string[] temp;

            if (dr == DialogResult.OK)
            {
                temp = Directory.GetFiles(@browser.SelectedPath);
                mypath = @browser.SelectedPath;
                txtPath.Text = mypath;
                for (int k = 0; k < temp.Length; k++)
                {
                    string extent = Path.GetExtension(temp[k]);
                    if (extent == ".jpg" || extent == ".gif")
                    {
                        listFile.Items.Add(Path.GetFileName(temp[k]));
                    }
                }
                listFile.Focus();
                listFile.SelectedIndex = 0;
                picPicture.Load(@mypath + @"\" + listFile.Items[0]);
                label1.Text = "第" + (1 + listFile.SelectedIndex).ToString() + "张 共" + listFile.Items.Count.ToString() + "张";

            }
            else
            {
                return;
            }
            
        }
        
        
  
        private void btnDonghua_Click(object sender, EventArgs e)
        {
            
            iWideth = 280;
            picPicture.Width = 0;
            timer1.Enabled = true;
           
        }

        

        private void timer1_Tick(object sender, EventArgs e)
        {
              if (picPicture.Width < iWideth)
                    picPicture.Width += 3;
            if (picPicture.Width >= iWideth)
                timer1.Enabled = false;
        }



    }
}

 

c#图片浏览

标签:

原文地址:http://www.cnblogs.com/-slient/p/5116838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!