//图片
List<string> pictures = new List<string>();
int i = 0;
private void btnOpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "请选择图片文件";
//openFileDialog.InitialDirectory = @"Picture";
openFileDialog.Multiselect = true;
openFileDialog.Filter = "图片文件|*.jpeg|所有文件|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string[] path = openFileDialog.FileNames;
for (int i = 0; i < path.Length; i++)
{
pictures.Add(path[i]);
}
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = Image.FromFile(pictures[0]);
pictureBox1.Show();
}
}
private void btnLast_Click(object sender, EventArgs e)
{
i--;
if (i == -1)
{
i = pictures.Count - 1;
}
pictureBox1.Image = Image.FromFile(pictures[i]);
}
private void btnNext_Click(object sender, EventArgs e)
{
i++;
if (i == pictures.Count)
{
i = 0;
}
pictureBox1.Image = Image.FromFile(pictures[i]);
}
//音乐播放器
List<string> songs = new List<string>();
private void btnOpenFileSong_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "请选择音乐文件";
//openFileDialog.InitialDirectory = @"Song";
openFileDialog.Multiselect = true;
openFileDialog.Filter = "音乐文件|*.wav|所有文件|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string[] path = openFileDialog.FileNames;
for (int i = 0; i < path.Length; i++)
{
listBox1.Items.Add(Path.GetFileName(path[i]));
songs.Add(path[i]);
}
}
}
SoundPlayer soundPlayer = new SoundPlayer();
private void listBox1_DoubleClick(object sender, EventArgs e)
{
soundPlayer.SoundLocation = songs[listBox1.SelectedIndex];
soundPlayer.Play();
}
private void btnLastSong_Click(object sender, EventArgs e)
{
int index = listBox1.SelectedIndex;
index--;
if (index == -1)
{
index = listBox1.Items.Count - 1;
}
listBox1.SelectedIndex = index;
soundPlayer.SoundLocation = songs[index];
soundPlayer.Play();
}
private void btnNextSong_Click(object sender, EventArgs e)
{
int index = listBox1.SelectedIndex;
index++;
if (index == listBox1.Items.Count)
{
index = 0;
}
listBox1.SelectedIndex = index;
soundPlayer.SoundLocation = songs[index];
soundPlayer.Play();
}