请教各位高人如题,正在只做一个简单的图片浏览器,
想设计一个按钮,功能类似AcdSee的浏览下一张图片,和浏览上一张图片。
具体代码应该怎么写呢,谢谢。
想设计一个按钮,功能类似AcdSee的浏览下一张图片,和浏览上一张图片。
具体代码应该怎么写呢,谢谢。
解决方案 »
- 控制textbox中只输入数字和小数点
- C# WinForm 的location属性设定
- winform下listbox绑定datareader数据源的问题
- winform下载的问题
- 请问我做的字库为TTF文件,怎么写C#程序读取字库让字在TEXTBOX控件中显示出来?
- textbox问题。
- C#中如何增,删,改,查SQL SERVER的IMAGE字段内容
- 求论坛的详细设计书
- Windows窗体中进度条功能实现,请各位帮忙!
- winform程序中如何获取DataGrid当前行改变啊?
- C#窗体开发中的更新,查询,删除,添加功能的实现
- asp.net(C#)怎样返回上一次打开的页面,就像浏览器的后退按钮一样、
<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>
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);
} }
}
/// <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();
}
} }
}
需要全部代码,发邮件给我吧。zhoufoxcn(at)qq.com