相册 C#.docx
- 文档编号:11971011
- 上传时间:2023-04-16
- 格式:DOCX
- 页数:53
- 大小:2.54MB
相册 C#.docx
《相册 C#.docx》由会员分享,可在线阅读,更多相关《相册 C#.docx(53页珍藏版)》请在冰豆网上搜索。
相册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;
///
///使用中のリソースをすべてクリーンアップします。
///
///
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.
///
///
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 相册 C#
![提示](https://static.bdocx.com/images/bang_tan.gif)