请教各位高人如题,正在只做一个简单的图片浏览器,
想设计一个按钮,功能类似AcdSee的浏览下一张图片,和浏览上一张图片。
具体代码应该怎么写呢,谢谢。

解决方案 »

  1.   

    你是前端控制 还是要跳转到新页面啊<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
    <script language="JavaScript" type="text/javascript">
    var imgs=["http://www.csdn.net/Images/logo_csdn.gif",
    "http://www.baidu.com/img/logo.gif",
    "http://www.google.com/intl/zh-CN_ALL/images/logo.gif",
    "http://images.sohu.com/uiue/sohu_logo/beijing2008/2008sohu.gif",
    "http://i3.sinaimg.cn/home/deco/2008/0325/sinahome_Logo.gif"];
    var i=-1;
    function NextImg()
    {
    if(i==imgs.length-1)i=-1;
    document.getElementById("imgX").src=imgs[++i];
    }
    function PreImg()
    {
    if(i==0)i=imgs.length;
    document.getElementById("imgX").src=imgs[--i];
    }
    </script>
     
     </HEAD> <BODY onload="NextImg()">
    <img id="imgX"/>
    <button onclick="PreImg()">上一张</button>
    <button onclick="NextImg()">下一张</button>
     </BODY>
    </HTML>
      

  2.   

    Button ButtonNext = new Button();
      

  3.   


    using System;
    using System.Collections;
    using System.IO;
    using System.Drawing;namespace PictureView
    {
    /// <summary>
    /// PictureLoader负责装载图片
    /// </summary>
    public class PictureLoader
    {
    private string path;
    #region 构造函数
    /// <summary>
    /// 无参构造函数,系统自动设置图片装载路径
    /// </summary>
    public PictureLoader()
    {
    InitPath();
    } /// <summary>
    /// 以指定路径构建实例
    /// </summary>
    /// <param name="path">图片路径</param>
    public PictureLoader(string path)
    {
    this.path=path;
    }
    #endregion /// <summary>
    /// 根据指定好的路径装载图片
    /// </summary>
    /// <returns>返回包含符合条件的图片名称的ArrayList集合</returns>
    public ArrayList LoadPicture()
    {
    if(path==null)
    {
    InitPath();
    } //ArrayList pictureList=new ArrayList();
                ArrayList<string> pictureList = new ArrayList<string>();
    System.IO.DirectoryInfo directoryInfo=new DirectoryInfo(path);
                #region 设置显示的图片类型为jpg、bmp、gif三种
                FileInfo[] jpgFiles=directoryInfo.GetFiles("*.jpg");
    FileInfo[] bmpFiles=directoryInfo.GetFiles("*.bmp");
    FileInfo[] gifFiles=directoryInfo.GetFiles("*.gif");
                #endregion            FileInfo[] pictureFiles=new FileInfo[jpgFiles.Length+bmpFiles.Length+gifFiles.Length];
    Array.Copy(jpgFiles,pictureFiles,jpgFiles.Length);
    Array.Copy(bmpFiles,0,pictureFiles,jpgFiles.Length,bmpFiles.Length);
    Array.Copy(gifFiles,0,pictureFiles,jpgFiles.Length+bmpFiles.Length,gifFiles.Length);            for (int i = 0; i < pictureFiles.Length; i++)
                {
                    pictureList.Add(pictureFiles[i].FullName);
                }
    return pictureList<string>;
    } /// <summary>
    /// 设置或者获取装载图片的路径
    /// </summary>
    public string Path
    {
    get
    {
    return path;
    }
    set
    {
    path=value;
    }
    } // 初始化图片装载路径
    private void InitPath()
    {
    path=System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);
    } }
    }
      

  4.   


    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
                //Application.Run(new MainForm());
                DrawForm df = new DrawForm();
                Application.Run(df);
    } private void MainForm_Load(object sender, System.EventArgs e)
    {
    this.sBPTime.Text=System.DateTime.Today.ToLongDateString();
    } private void btnSelectPath_Click(object sender, System.EventArgs e)
    {
    System.Windows.Forms.DialogResult result=this.folderBrowserDialog.ShowDialog(this);
    if(result==System.Windows.Forms.DialogResult.OK)
    {
    PictureLoader pictureLoader=new PictureLoader(this.folderBrowserDialog.SelectedPath);
    pictureList=pictureLoader.LoadPicture();
    this.tbPath.Text=this.folderBrowserDialog.SelectedPath;
                    if (pictureList.Count > 0)
                    {
                        index = 0;
                        BindPicture();
                    }
                    else
                    {
                        MessageBox.Show(this, "在指定的目录没有发现任何图片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
    }
    } /// <summary>
    /// 绑定图片
    /// </summary>
    private void BindPicture()
    {
    //this.pictureBox.Image=(Bitmap)pictureList[index];
                string imagePath = pictureList[index] as string;
                Image image = Image.FromFile(imagePath);
                this.pictureBox.Image = image;
    this.sBPTotal.Text=String.Format("共{0}张",pictureList.Count);
    this.sBPCurrent.Text=String.Format("当前是第{0}张",index+1);
    } private void btnFirst_Click(object sender, System.EventArgs e)
    {
    if(pictureList.Count>0)//判断是否有图片
    {
    index=0;
    BindPicture();
    }
    //BindPicture();这是我最初写的代码,注意想想为什么不能写在这里(存在没有图片的情况)
    } //下一张
    private void btnPrevious_Click(object sender, System.EventArgs e)
    {
    if(pictureList.Count>0)
    {
    index--;
    if(index<0)//判断数组索引递减之后是否小于0,即是否数组下标越界
    {
    index=pictureList.Count-1;
    }
    BindPicture();
    }
    //BindPicture();
    } private void btnNext_Click(object sender, System.EventArgs e)
    {
    if(pictureList.Count>0)
    {
    index++;
    if(index>pictureList.Count-1)//判断是否超过数组最大索引
    {
    index=0;
    }
    BindPicture();
    }
    } private void btnLast_Click(object sender, System.EventArgs e)
    {
    if(pictureList.Count>0)//判断是否有图片
    {
    index=pictureList.Count-1;
    BindPicture();
    }
    } }
    }
      

  5.   

    以前讲课的时候做过这样的项目,主要是用一个集合保存所有图片路径,点下一个的时候取集合中下一个图片路径加载显示就行了。
    需要全部代码,发邮件给我吧。zhoufoxcn(at)qq.com