相册 C#.docx

上传人:b****4 文档编号:11971011 上传时间:2023-04-16 格式:DOCX 页数:53 大小:2.54MB
下载 相关 举报
相册 C#.docx_第1页
第1页 / 共53页
相册 C#.docx_第2页
第2页 / 共53页
相册 C#.docx_第3页
第3页 / 共53页
相册 C#.docx_第4页
第4页 / 共53页
相册 C#.docx_第5页
第5页 / 共53页
点击查看更多>>
下载资源
资源描述

相册 C#.docx

《相册 C#.docx》由会员分享,可在线阅读,更多相关《相册 C#.docx(53页珍藏版)》请在冰豆网上搜索。

相册 C#.docx

相册C#

Winfrom相册(C#)

突发有感,用C#(VS2008)做了相册。

大概功能有:

加载图片、排序图片、旋转图片、上下切换图片、右键菜单。

程序简单易懂可扩展(后文将提到)。

没有用到数据库,所以我们看到的都是功能,而不能保存数据。

运行截图:

工程截图:

1,Photo文件夹。

里面是一些照片,运行截图的第一张里面的图片。

使用时将它拷贝到C盘根目录即可。

当然,大家也可以自己放一些照片到这个文件夹下。

2,CtlPicShow。

自定义控件

3,FrmBigPhoto。

运行截图的第二张

4,FrmPhotos。

运行截图的第一张

5,PhotoManager。

数据管理Class

功能简述:

初期运行时,画面图如下所示:

可以看到画面上是什么都没有的。

一些提示信息需要看一下。

1.图片存放路径:

【C:

\Photo】这是程序里面写死的路径(各位如果拿到源代码的话,可以自己修改;甚至可以将这个路径作为画面的输入项,自由指定)。

我在工程包里面已经放了一些好看的照片了,可以直接把工程里面的Photo文件夹拷贝到C盘根目录下。

2.图片数量限制:

【100】同上所述,也是程序里面写死的(同样可以自己扩展修改)。

意思是本相册最多只接受100张相片。

3.图片格式限制:

【*.jpg*.png】同上所述,也是程序里面写死的。

图片的格式有很多,为演示,本相册只接受以上2种格式的图片文件。

点击按钮【加载图片】,效果如下:

可以看到,将【C:

\Photo】下的照片显示到画面中了。

排序照片:

选中照片(勾选CheckBox),点击上移、下移即可排序照片。

排序规则如下:

ABCD…代表未勾选的照片,a1a2a3…代表已勾选的照片,他们的原顺序A、a1、a2、B、C、a3。

单击上移时,效果:

a1、a2、A、B、a3、C

单击下移时,效果:

A、B、a1、a2、C、a3

(说的有点麻烦,其实想一想,意思很简单……)

旋转照片:

双击任意一张照片,可以打开照片的单独页面,如下所示:

此时可以点击按钮【左旋转】、【右旋转】查看效果,效果图如下:

此时还可以点击按钮【上一张】、【下一张】浏览照片。

(可以扩展功能,实现自动播放功能。

按下Esc,回到主页面。

右键任意一个照片,存在右键菜单。

点击【设为头像】,则左上角的头像即被设定(可以随时设定任意的图片为头像):

点击【路径】,则弹出提示框,提示此图片的路径:

点击【放大】,其效果跟双击一样,前文已提到,不再赘述。

可扩展功能:

主要是右键菜单。

前文提到的右键菜单的3个功能只是很简单的例子,其实想到什么都可以在此实现。

只要知道了我们点击的是哪张照片,接下来什么事都好办!

一开始也提到,本程序没有用到数据库,其实可以使用数据库保存图片等操作信息。

程序代码:

如果需要源码,请发邮件至:

tang.peng.ju@

【CtlPicShow.cs】

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Drawing;

usingSystem.Data;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.IO;

namespacePhotoManager

{

publicpartialclassCtlPicShow:

UserControl

{

///

图片单击事件

publicMouseEventHandlerPicMouseRightClick;

///

图片双击事件

publicMouseEventHandlerPicMouseDoubleClick;

///

图片信息

privatePhotoFilephotoInfo;

///

文件路径

publicstringFileName

{

get{returnthis.photoInfo.FileName;}

}

///

///构造方法

///

///

publicCtlPicShow(PhotoFilephotoFile)

{

InitializeComponent();

//数据信息

this.photoInfo=photoFile;

//控件内容显示

this.RefreshPhoto();

}

///

///显示数据

///

publicvoidRefreshPhoto()

{

//显示到控件

this.pbPhoto.Image=PhotoManager.GetImageThumbnail(photoInfo.FileName,this.pbPhoto.Size);

this.chkSel.Text=photoInfo.Name;

this.chkSel.Checked=photoInfo.IsChecked;

}

///

///鼠标点击

///

///

///

privatevoidpbPhoto_MouseClick(objectsender,MouseEventArgse)

{

if(e.Button==MouseButtons.Right&&

this.PicMouseRightClick!

=null)

{

this.PicMouseRightClick(this,e);

}

}

///

///鼠标双击

///

///

///

privatevoidpbPhoto_MouseDoubleClick(objectsender,MouseEventArgse)

{

if(e.Button==MouseButtons.Left&&

this.PicMouseDoubleClick!

=null)

{

this.PicMouseDoubleClick(this,e);

}

}

///

///选中状态记录

///

///

///

privatevoidchkSel_CheckedChanged(objectsender,EventArgse)

{

this.photoInfo.IsChecked=this.chkSel.Checked;

}

}

}

 

【CtlPicShow.Designer.cs】

namespacePhotoManager

{

partialclassCtlPicShow

{

///

///必要なデザイナ変数です。

///

privateSystem.ComponentModel.IContainercomponents=null;

///

///使用中のリソースをすべてクリーンアップします。

///

///マネージリソースが破棄される場合true、破棄されない場合はfalseです。

protectedoverridevoidDispose(booldisposing)

{

if(disposing&&(components!

=null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#regionコンポーネントデザイナで生成されたコード

///

///デザイナサポートに必要なメソッドです。

このメソッドの内容を

///コードエディタで変更しないでください。

///

privatevoidInitializeComponent()

{

this.pbPhoto=newSystem.Windows.Forms.PictureBox();

this.chkSel=newSystem.Windows.Forms.CheckBox();

((System.ComponentModel.ISupportInitialize)(this.pbPhoto)).BeginInit();

this.SuspendLayout();

//

//pbPhoto

//

this.pbPhoto.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Bottom)

|System.Windows.Forms.AnchorStyles.Left)

|System.Windows.Forms.AnchorStyles.Right)));

this.pbPhoto.Location=newSystem.Drawing.Point(0,0);

this.pbPhoto.Name="pbPhoto";

this.pbPhoto.Size=newSystem.Drawing.Size(200,160);

this.pbPhoto.TabIndex=0;

this.pbPhoto.TabStop=false;

this.pbPhoto.MouseDoubleClick+=newSystem.Windows.Forms.MouseEventHandler(this.pbPhoto_MouseDoubleClick);

this.pbPhoto.MouseClick+=newSystem.Windows.Forms.MouseEventHandler(this.pbPhoto_MouseClick);

//

//chkSel

//

this.chkSel.AutoSize=true;

this.chkSel.Location=newSystem.Drawing.Point(3,165);

this.chkSel.Name="chkSel";

this.chkSel.Size=newSystem.Drawing.Size(72,16);

this.chkSel.TabIndex=1;

this.chkSel.Text="FileName";

this.chkSel.UseVisualStyleBackColor=true;

this.chkSel.CheckedChanged+=newSystem.EventHandler(this.chkSel_CheckedChanged);

//

//CtlPicShow

//

this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);

this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;

this.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;

this.Controls.Add(this.chkSel);

this.Controls.Add(this.pbPhoto);

this.Font=newSystem.Drawing.Font("SimSun",9F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(0)));

this.Name="CtlPicShow";

this.Size=newSystem.Drawing.Size(200,184);

((System.ComponentModel.ISupportInitialize)(this.pbPhoto)).EndInit();

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

privateSystem.Windows.Forms.PictureBoxpbPhoto;

privateSystem.Windows.Forms.CheckBoxchkSel;

}

}

【FrmBigPhoto】

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.IO;

namespacePhotoManager

{

publicpartialclassFrmBigPhoto:

Form

{

///

主画面同步

publicDelegateShowTargetPhotoShowTargetPhoto;

privatePhotoManagerdataManager;

privateintphotoIndex;

publicFrmBigPhoto(PhotoManagerdataManager,intphotoIndex)

{

InitializeComponent();

this.dataManager=dataManager;

this.photoIndex=photoIndex;

ShowImage(false);

}

///

///图片显示

///

///主画面图片同步标志

privatevoidShowImage(boolsynFlg)

{

bool[]status=this.dataManager.CheckStatus(photoIndex);

this.btnPre.Enabled=status[0];

this.btnNext.Enabled=status[1];

this.lblPage.Text=string.Format("{0}/{1}",(photoIndex+1),this.dataManager.PhotoCount);

stringfileName=dataManager.GetFileName(photoIndex);

this.Text=Path.GetFileName(fileName);

if(File.Exists(fileName))

{

this.pbPhoto.Image=Bitmap.FromFile(fileName);

}

else

{

this.lblNoneTip.Visible=true;

this.btnLeft.Enabled=false;

this.btnRight.Enabled=false;

}

if(synFlg&&

this.ShowTargetPhoto!

=null)

{

this.ShowTargetPhoto(photoIndex);

}

}

///

///Esc退出功能

///

///

///

privatevoidFrmBigPhoto_KeyPress(objectsender,KeyPressEventArgse)

{

if((int)e.KeyChar==(int)Keys.Escape)

{

this.Close();

}

}

///

///左旋转

///

///

///

privatevoidbtnLeft_Click(objectsender,EventArgse)

{

if(this.pbPhoto.Image==null)return;

this.pbPhoto.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);

this.pbPhoto.Refresh();

}

///

///右旋转

///

///

///

privatevoidbtnRight_Click(objectsender,EventArgse)

{

if(this.pbPhoto.Image==null)return;

this.pbPhoto.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);

this.pbPhoto.Refresh();

}

///

///上一张

///

///

///

privatevoidbtnPre_Click(objectsender,EventArgse)

{

photoIndex--;

ShowImage(true);

}

///

///下一张

///

///

///

privatevoidbtnNext_Click(objectsender,EventArgse)

{

photoIndex++;

ShowImage(true);

}

}

}

【FrmBigPhoto.Designer.cs】

namespacePhotoManager

{

partialclassFrmBigPhoto

{

///

///Requireddesignervariable.

///

privateSystem.ComponentModel.IContainercomponents=null;

///

///Cleanupanyresourcesbeingused.

///

///trueifmanagedresourcesshouldbedisposed;otherwise,false.

protectedoverridevoidDispose(booldisposing)

{

if(disposing&&(components!

=null))

{

components.Dispose();

}

if(this.pbPhoto.Image!

=null)

{

this.pbPhoto.Image.Dispose();

this.pbPhoto.Image=null;

}

base.Dispose(disposing);

}

#regionWindowsFormDesignergeneratedcode

///

///RequiredmethodforDesignersupport-donotmodify

///thecontentsofthismethodwiththecodeeditor.

///

privatevoidInitializeComponent()

{

this.pbPhoto=newSystem.Windows.Forms.PictureBox();

this.btnLeft=newSystem.Windows.Forms.Button();

this.btnRight=newSystem.Windows.Forms.Button();

this.lblNoneTip=newSystem.Windows.Forms.Label();

this.btnPre=newSystem.Windows.Forms.Button();

this.btnNext=newSystem.Windows.Forms.Button();

this.lblPage=newSystem.Windows.Forms.Label();

((System.ComponentModel.ISupportInitialize)(this.pbPhoto)).BeginInit();

this.SuspendLayo

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1