📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.PictureBox picPhoto;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.OpenFileDialog dlgOpenPhoto;
private System.Windows.Forms.SaveFileDialog dlgSavePhoto;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Panel pnlFrame;
PictureBox[] frames;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.pnlFrame = new System.Windows.Forms.Panel();
this.picPhoto = new System.Windows.Forms.PictureBox();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.dlgOpenPhoto = new System.Windows.Forms.OpenFileDialog();
this.dlgSavePhoto = new System.Windows.Forms.SaveFileDialog();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "加载边框";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "选择照片";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// pnlFrame
//
this.pnlFrame.AutoScroll = true;
this.pnlFrame.Dock = System.Windows.Forms.DockStyle.Left;
this.pnlFrame.Location = new System.Drawing.Point(0, 0);
this.pnlFrame.Name = "pnlFrame";
this.pnlFrame.Size = new System.Drawing.Size(168, 413);
this.pnlFrame.TabIndex = 0;
//
// picPhoto
//
this.picPhoto.Dock = System.Windows.Forms.DockStyle.Fill;
this.picPhoto.Location = new System.Drawing.Point(168, 0);
this.picPhoto.Name = "picPhoto";
this.picPhoto.Size = new System.Drawing.Size(592, 413);
this.picPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.picPhoto.TabIndex = 1;
this.picPhoto.TabStop = false;
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "照片保存";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(760, 413);
this.Controls.Add(this.picPhoto);
this.Controls.Add(this.pnlFrame);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
string[] files=Directory.GetFiles(Application.StartupPath+"\\frames");
this.frames=new PictureBox[files.Length];
//请注意不是图片文件
for(int i=0;i<files.Length-1;i++)
{
this.frames[i]=new PictureBox();
this.frames[i].Location=new Point(0,i*this.pnlFrame.Width);
this.frames[i].Width=this.pnlFrame.Width-20;
this.frames[i].Height=this.pnlFrame.Width;
this.frames[i].SizeMode=PictureBoxSizeMode.StretchImage;
this.frames[i].Image=Image.FromFile(files[i]);
this.pnlFrame.Controls.Add(this.frames[i]);
this.frames[i].Visible=true;
this.frames[i].Click+=new EventHandler(frames_Click);
}
}
private void frames_Click(object sender, EventArgs e)
{
//请注意照片存在否??
this.picPhoto.Image=Image.FromFile(this.dlgOpenPhoto.FileName);
Graphics g=Graphics.FromImage(this.picPhoto.Image);
Bitmap b=(Bitmap)((PictureBox)sender).Image;
b.MakeTransparent(Color.Black);
g.DrawImage(b,new Rectangle(0,0,this.picPhoto.Image.Width,this.picPhoto.Image.Height));
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.dlgOpenPhoto.Filter="(JPG文件*.jpg)|*.jpg|(BMP文件)|*.bmp";
this.dlgOpenPhoto.InitialDirectory=Application.StartupPath;
DialogResult dr=this.dlgOpenPhoto.ShowDialog(this);
if(dr==DialogResult.OK)
{
this.picPhoto.Image=Image.FromFile(this.dlgOpenPhoto.FileName);
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.dlgSavePhoto.Filter="(JPG图片 *.jpg)|*.jpg";
DialogResult dr=this.dlgSavePhoto.ShowDialog(this);
if(dr==DialogResult.OK)
{
this.picPhoto.Image.Save(this.dlgSavePhoto.FileName);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -