简易的照片浏览器

来源:互联网 发布:js每天定时执行 编辑:程序博客网 时间:2024/06/10 06:35

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 照片浏览器
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
//添加照片
        private void button1_Click(object sender, EventArgs e)
        
{
            openFileDialog1.ShowDialog();
            
string[] files = openFileDialog1.FileNames;
            
for (int i = 0; i < files.Length; i++)
            
{
                listBox1.Items.Add(files[i].ToString());
            }

        }


        
//选中照片并显示
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        
{
            
string path = listBox1.SelectedItem.ToString();
            
//方法一
            pictureBox1.ImageLocation = path;
            
//方法二
            
//pictureBox1.Image = Image.FromFile(path);
        }


        
//上一张
        private void button2_Click(object sender, EventArgs e)
        
{

            
if (listBox1.SelectedIndex < 1)
                listBox1.SelectedIndex 
= listBox1.Items.Count-1;
            
else
            
{
                
int i = listBox1.SelectedIndex;
                listBox1.SelectedIndex 
= --i;
            }

           
        }



        
//下一张
        private void button3_Click_1(object sender, EventArgs e)
        
{
            
if (listBox1.SelectedIndex > listBox1.Items.Count-2)
                listBox1.SelectedIndex 
= 0;
            
else
            
{
                
int i = listBox1.SelectedIndex;
                listBox1.SelectedIndex 
= ++i;
            }

        }


        
//时钟设置
        private void timer1_Tick(object sender, EventArgs e)
        
{
            
if (listBox1.SelectedIndex > listBox1.Items.Count - 2)
                listBox1.SelectedIndex 
= 0;
            
else
            
{
                
int i = listBox1.SelectedIndex;
                listBox1.SelectedIndex 
= ++i;
            }

        }


        
//自动播放
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        
{
            timer1.Enabled 
= !timer1.Enabled;
        }


        
private void pictureBox1_Click(object sender, EventArgs e)
        
{

        }



    }

}

 

原创粉丝点击