注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

C#图片浏览器,制作  

2015-06-01 21:32:48|  分类: C#基础 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
C#图片浏览器,制作 - 983433479 - 告别迷茫
 1.主要的功能,可以查看图片就好了,自动的上下一张
2.能购自适应,永远的居中显示
3.放大缩小的设置
4.弄的不是特别的好,不要吐槽


主要的代码如下   http://pan.baidu.com/s/1qWG9xSw

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.Collections;
using System.IO;

namespace 图片浏览器
{
public partial class Form1 : Form
{

ArrayList path = new ArrayList();
int index = 0;
string picPath="";
int pictureWide=0;
int pictureHeight=0;
public Form1()
{
InitializeComponent();
}
private void 选择照片ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog();
openfile.Filter = "JPG(*.JPG;*.JPEG);gif文件(*.GIF);BMP文件(*.BMP);PNG文件(*.PNG)|*.jpg;*.jpeg;*.gif;*.bmp;*.png";
if (openfile.ShowDialog() == DialogResult.OK)
{
picPath = openfile.FileName;
Show();
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
}
PathInit(openfile.FileName);
}
private void PathInit(string s)
{
int i = 0;
string PathWnJian="";
for ( i = s.Length - 1; i >= 0; i--)
{

if (s[i] == '\\')
break;
}
PathWnJian=s.Substring(0,i);
DirectoryInfo Dinfo = new DirectoryInfo(PathWnJian);
FileInfo[] flies;
flies = Dinfo.GetFiles();
int j=0;
foreach(FileInfo t in flies)
{

if (t.Extension == ".JPG"||t.Extension==".jpg"||t.Extension==".PNG"||t.Extension==".png")
{path.Add(PathWnJian+"\\"+t.Name);j++;}
if ((PathWnJian + "\\" + t.Name) == s)
{
index = j-1;
//MessageBox.Show(index.ToString());
}
}

}
private void 退出TToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if (++index == path.Count)
index = 0;
picPath = (string)path[index];
Show();

}
private void button1_Click(object sender, EventArgs e)
{
if (--index == -1)
index = path.Count-1;
picPath = (string)path[index];
Show();
}
private void Show()//这里是我们的弄的重点,按照长宽比显示。
{
Image pic = Image.FromFile(picPath);//strFilePath是该图片的绝对路径
int intWidth = pic.Width;//长度像素值
int intHeight = pic.Height;//高度像素值
pictureWide = (this.Height - groupBox1.Height - menuStrip1.Height) * pic.Width / pic.Height;
pictureHeight = (this.Height - groupBox1.Height - menuStrip1.Height) ;
if (pictureWide > this.Width)
{
pictureWide = this.Width;
pictureHeight = pictureWide * intHeight / intWidth;
}
pictureBox1.Image = Image.FromFile(picPath);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Size = new Size(pictureWide, pictureHeight);
pictureBox1.Location = new Point((this.Width-pictureWide)/2,menuStrip1.Height+(this.Height-menuStrip1.Height-groupBox1.Height-pictureHeight)/2);

}
private void Form1_Resize(object sender, EventArgs e)
{
int wide4_1 = this.Width / 4;
int bian = 25;
this.button1.Location = new Point(bian, 15);
this.button2.Location = new Point(bian+wide4_1,15);
this.button3.Location = new Point(bian+wide4_1*2,15);
this.button4.Location = new Point(bian+wide4_1*3,15);
if(picPath!="")
Show();
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{

}
private void Form1_Load(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
}
private void Bigger()
{
int centralX=this.Width/2;
int centralY=(this.Height-menuStrip1.Height-groupBox1.Height)/2;
Image pic = Image.FromFile(picPath);//strFilePath是该图片的绝对路径
int intWidth = pic.Width;//长度像素值
int intHeight = pic.Height;//高度像素值
pictureWide += (pictureWide/10);
pictureHeight += (pictureHeight/10);
int x1 = centralX-pictureWide/2;
int y1 = centralY-pictureHeight/2;
pictureBox1.Image.Dispose();
pictureBox1.Image = Image.FromFile(picPath);

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Size = new Size(pictureWide, pictureHeight);
pictureBox1.Location = new Point(x1,y1);


}
private void smoller()
{
int centralX = this.Width / 2;
int centralY = (this.Height - menuStrip1.Height - groupBox1.Height) / 2;
Image pic = Image.FromFile(picPath);//strFilePath是该图片的绝对路径
int intWidth = pic.Width;//长度像素值
int intHeight = pic.Height;//高度像素值
if((pictureWide)>10)
pictureWide -=(pictureWide/10);
if((pictureHeight)>10)
pictureHeight -= (pictureHeight/10);
int x1 = centralX - pictureWide / 2;
int y1 = centralY - pictureHeight / 2;
pictureBox1.Image.Dispose();
pictureBox1.Image = Image.FromFile(picPath);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Size = new Size(pictureWide, pictureHeight);
pictureBox1.Location = new Point(x1, y1);
}
private void button3_Click(object sender, EventArgs e)
{
Bigger();
}
private void button4_Click(object sender, EventArgs e)
{
smoller();
}
}
}



  评论这张
 
阅读(1)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017