📄 mainform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace MyPhotos
{
/// <summary>
/// Summary description for MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnLoad;
private System.Windows.Forms.PictureBox pbxPhoto;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MainForm()
{
// Required for Windows Form Designer support
InitializeComponent();
// Set the application title bar
Version ver = new Version(Application.ProductVersion);
this.Text = String.Format("MyPhotos {0:#}.{1:#}", ver.Major, ver.Minor);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLoad = new System.Windows.Forms.Button();
this.pbxPhoto = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// btnLoad
//
this.btnLoad.Location = new System.Drawing.Point(8, 8);
this.btnLoad.Name = "btnLoad";
this.btnLoad.TabIndex = 0;
this.btnLoad.Text = "&Load";
this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
//
// pbxPhoto
//
this.pbxPhoto.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.pbxPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pbxPhoto.Location = new System.Drawing.Point(24, 56);
this.pbxPhoto.Name = "pbxPhoto";
this.pbxPhoto.Size = new System.Drawing.Size(248, 192);
this.pbxPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pbxPhoto.TabIndex = 1;
this.pbxPhoto.TabStop = false;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pbxPhoto,
this.btnLoad});
this.MinimumSize = new System.Drawing.Size(200, 200);
this.Name = "MainForm";
this.Text = "MyPhotos";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void btnLoad_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open Photo";
dlg.Filter = "jpg files (*.jpg)|*.jpg"
+ "|All files (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
pbxPhoto.Image = new Bitmap(dlg.OpenFile());
}
catch (Exception ex)
{
// Handle exception
MessageBox.Show("Unable to load file: " + ex.Message);
}
}
dlg.Dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -