WinForm 做浏览图片的东西

来源:百度知道 编辑:UC知道 时间:2024/05/23 10:53:29
WinForm下用控件pictureBox,和两个按钮,浏览存放在文件夹里的一组图片(全屏浏览),点一下按钮按图片编号顺序换下一张图片,浏览完后,点另一个按钮,回到第一张.谢谢各位我会追加分的..这是代码点击按纽后没反映,不能浏览图片,请帮我改下
定义几个私有变量
private int IndexPicture = 0;
private int MaxLength = 0;
private string[] Picturename = new string[100];
--------------------------------------------------------
private void OpenFileBtn_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Picture file(*.gif)|*.gif|所有文件(*.*)|*.*";
dlg.Multiselect = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
for (int i = 0; i < dlg.FileNames.Length; i++)
{
MaxLength = dlg.FileNames.Length;
Picturename[i] = dlg.FileNames[i].ToString();
}
}
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[IndexPicture]);

}

private void button1_Click(object sender, System.EventArgs e)

自己做的.编译通过.你可以COPY到VS去试试..和你的代码只是参数不同,可以试情况修改..图片路径取本机文件.注意图片后缀正确..
我是用VS2005做的..如果你是用03,要做适当调整..
---------form1.cs的代码---------------

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();
}

int index = 0;

private void 下一张按钮_Click(object sender, EventArgs e)
{
index++;

if (index == 9) index = 1;//循环

switch (index)
{
case 1:
this.pictureBox1.Image = System.Drawing.Image.FromFile(@"E:\NET平台\浏览图片\浏览图片\bin\Debug\1.jpg"); break;

case 2: