图片查看器
一个图片查看器
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.Media;
namespace windows1
{
public partial class Form1 : Form
{
private int count = 0;
private string strPath;
SoundPlayer sp;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.SelectedIndex = 0;
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.Desktop;
string strfilename = "";
string strExtfilename = "";
if (fbd.ShowDialog() ==DialogResult.OK)
{
this.listBox1.Items.Clear();
strPath = fbd.SelectedPath;
string[] filenames = Directory.GetFiles(fbd.SelectedPath);
for (int i = 0; i < filenames.Length; i++)
{
strfilename = filenames[i].Substring(filenames[i].LastIndexOf("\\")+1);
strExtfilename = filenames[i].Substring(filenames[i].LastIndexOf("."));
if (strExtfilename.ToLower() == ".jpg" || strExtfilename.ToLower() ==
".gif")
{
this.listBox1.Items.Add(strfilename);
}
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.listBox1.Items.Count > 0)
{
if (count >= this.listBox1.Items.Count)
{
count = 0;
}
this.listBox1.SelectedIndex = count;
if (this.pictureBox1.Image != null)
{
this.pictureBox1.Image.Dispose();
}
this.pictureBox1.Image = Image.FromFile(strPath + "\\"+this.listBox1.Items[count]);
count++;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
count = this.listBox1.SelectedIndex;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.timer1.Interval = (this.comboBox1.SelectedIndex + 1) * 500;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (count > 0)
{
if (this.button2.Text == "暂停")
{
this.timer1.Stop();
this.button2.Text = "继续";
}
else
{
this.timer1.Start();
this.button2.Text = "暂停";
}
}
}
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.wav|*.wav";
if (ofd.ShowDialog() == DialogResult.OK)
{
if (sp != null)
{
sp.Dispose();
}
sp = new SoundPlayer(ofd.FileName);
sp.PlayLooping();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (sp != null)
{
if (this.button3.Text == "停止播放")
{
sp.Stop();
this.button3.Text = "启动播放";
}
else
{
sp.PlayLooping();
this.button3.Text = "停止播放";
}
}
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}