2022-05-02时隔了好久写了C#程序

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Microsoft.VisualBasic;




namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.MouseWheel += new System.Windows.Forms.MouseEventHandler(FanYe_MouseWheel);
            this.label1.BringToFront();
            
        }
        
        ArrayList filList = new ArrayList();
        
        private void DirectoryInfo(string path, string extension)
        {
            DirectoryInfo directoryInfo1 = new DirectoryInfo(path);
            
            foreach (FileSystemInfo file in directoryInfo1.GetFileSystemInfos())
            {
                if(file is DirectoryInfo)
                {
                    DirectoryInfo(file.FullName.ToString(), extension);
                }
                if (Path.GetExtension(file.ToString()) == extension)
                {
                    filList.Add(file.FullName);
                }   
            }
            
            
        }
 /*       private void DirectoryInfo(string path,string extension)
        {
            DirectoryInfo directoryInfo1 = new DirectoryInfo(path);
            if(directoryInfo1.GetFiles().Length > 0)
            {
                foreach(FileInfo i in directoryInfo1.GetFiles())
                {

                    
                    if (Path.GetExtension(i.ToString())==extension)
                    {
                        filList.Add(i.FullName.ToString());
                    }
                    
                }
               
            }

            foreach (DirectoryInfo i in directoryInfo1.GetDirectories())
            {

                this.DirectoryInfo(i.FullName.ToString(),extension);
            }

        }*/
        private Random random = new Random();
        private string folderSelectedPath;
        private void button1_Click(object sender, EventArgs e)
        {
            //string extension = Interaction.InputBox("输入文件后缀名:","输入");

            string extension = ".jpg";
            ArrayList dirList = new ArrayList();
            FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
            folderBrowser.ShowDialog();
            folderSelectedPath = folderBrowser.SelectedPath;
            this.DirectoryInfo(folderSelectedPath,extension);
            button1.Visible = false;
            button4.Visible = false;
            StreamWriter sw = new StreamWriter(folderSelectedPath + "/cache.txt");
            foreach (string strPath in filList)
            {
                if (Path.GetExtension(strPath) == extension)
                {
                    sw.WriteLine(strPath);
                }
            }
            sw.Close();
            pictureBox1.Visible = true;
            pictureBox1.Image = Image.FromFile(filList[0].ToString());
            //全屏
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            Rectangle ret = Screen.GetWorkingArea(this);//大概返回显示器分辨率
            this.pictureBox1.ClientSize = new Size(ret.Width, ret.Height);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            this.pictureBox1.Dock = DockStyle.Fill;
            this.label1.Text = Convert.ToString(filList.Count);
            this.numericUpDown1.Maximum = filList.Count;
            


        }
        int PicIndx = 1;
        
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            
            pictureBox1.Image = Image.FromFile(filList[PicIndx].ToString());
            PicIndx += 1;
            if (PicIndx >= filList.Count)
            {
                MessageBox.Show("overRange", "tips", MessageBoxButtons.OK);
                PicIndx -= 1;
            }
            this.label1.Text = Convert.ToString(PicIndx);
            textBox1.Text = Convert.ToString(filList.Count);
            numericUpDown1.Value = PicIndx;

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        //private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        //{

        //    //if (MessageBox.Show("close?","exit",MessageBoxButtons.OKCancel)==DialogResult.OK)
        //    //{
        //    //    this.WindowState = FormWindowState.Minimized;

        //    //}
            
        //}
        private void FanYe_MouseWheel(object sender,MouseEventArgs e)
        {
            if (e.Delta<0)
            {
                PicIndx += 10;
                if (PicIndx>=filList.Count)
                {
                    MessageBox.Show("overRange", "tips", MessageBoxButtons.OK);
                    PicIndx -= 10;
                }
                this.label1.Text = Convert.ToString(PicIndx);
                pictureBox1.Image = Image.FromFile(filList[PicIndx].ToString());
                textBox1.Text = Convert.ToString(filList.Count);
                numericUpDown1.Value = PicIndx;
            }
            else
            {
                PicIndx -= 10;
                this.label1.Text = Convert.ToString(PicIndx);
                pictureBox1.Image = Image.FromFile(filList[PicIndx].ToString());
                textBox1.Text = Convert.ToString(filList.Count);
                numericUpDown1.Value = PicIndx;
            }
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
            GC.Collect();
            this.WindowState = FormWindowState.Minimized;
            //if (MessageBox.Show("Minimized?", "Minimized", MessageBoxButtons.OKCancel) == DialogResult.OK)
            //{
            //    this.WindowState = FormWindowState.Minimized;
            //    textBox1.Text = Convert.ToString(filList.Count);
            //    numericUpDown1.Value = PicIndx;

            //}
        }

        private void textBox1_DoubleClick(object sender, EventArgs e)
        {
            GC.Collect();
            PicIndx = Convert.ToInt32(textBox1.Text);
            if (PicIndx >= filList.Count)
            {
                MessageBox.Show("overRange", "tips", MessageBoxButtons.OK);
                PicIndx = filList.Count-1;
            }
            this.label1.Text = Convert.ToString(PicIndx);
            pictureBox1.Image = Image.FromFile(filList[PicIndx].ToString());
            textBox1.Text = Convert.ToString(filList.Count);
            numericUpDown1.Value = PicIndx;
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            GC.Collect();
            PicIndx = Convert.ToInt32(numericUpDown1.Value);
            if (PicIndx >= filList.Count)
            {
                MessageBox.Show("overRange", "tips", MessageBoxButtons.OK);
                PicIndx = filList.Count - 1;
            }
            this.label1.Text = Convert.ToString(PicIndx);
            pictureBox1.Image = Image.FromFile(filList[PicIndx].ToString());
            textBox1.Text = Convert.ToString(filList.Count);
            numericUpDown1.Value = PicIndx;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            GC.Collect();
            
            PicIndx =random.Next(filList.Count);
            if (PicIndx >= filList.Count)
            {
                MessageBox.Show("overRange", "tips", MessageBoxButtons.OK);
                PicIndx = filList.Count - 1;
            }
            this.label1.Text = Convert.ToString(PicIndx);
            pictureBox1.Image = Image.FromFile(filList[PicIndx].ToString());
            textBox1.Text = Convert.ToString(filList.Count);
            numericUpDown1.Value = PicIndx;

        }

        private void button4_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
            folderBrowser.ShowDialog();
            folderSelectedPath = folderBrowser.SelectedPath;
            StreamReader sr = new StreamReader(folderSelectedPath+"/cache.txt");
            foreach(string i in sr.ReadToEnd().Split('\n'))
            {
                filList.Add(i);
            }
            
            sr.Close();
            button1.Visible = false;
            button4.Visible = false;
            pictureBox1.Visible = true;
            pictureBox1.Image = Image.FromFile(filList[0].ToString());
            //全屏
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            Rectangle ret = Screen.GetWorkingArea(this);//大概返回显示器分辨率
            this.pictureBox1.ClientSize = new Size(ret.Width, ret.Height);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            this.pictureBox1.Dock = DockStyle.Fill;
            this.label1.Text = Convert.ToString(filList.Count);
            this.numericUpDown1.Maximum = filList.Count;
        }
    }
}

你可能感兴趣的:(2022-05-02时隔了好久写了C#程序)