Monday, December 22, 2008

my first windows form

Form1.Designer.cs

using System.Windows.Forms;
using System.Drawing;
namespace MyForm
{
partial class Form1
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(54, 28);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Load";
this.button1.UseVisualStyleBackColor = true;
this.button1.Left = 10;
this.button1.Top = 10;
this.button1.Click += new System.EventHandler(this.HandleLoadClick);
this.button1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(54, 85);
this.pictureBox1.Name = "pictureBox1";
//this.pictureBox1.Size = new System.Drawing.Size(179, 119);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Width = this.Width / 2;
this.pictureBox1.Height = this.Height / 2;
pictureBox1.Left = (this.Width - pictureBox1.Width) / 2;
pictureBox1.Top = (this.Height - pictureBox1.Height) / 2;
this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
this.pictureBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(476, 327);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Hello Form";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);

}

#endregion

private void HandleLoadClick(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)
{
pictureBox1.Image = new Bitmap(dlg.OpenFile());
}
dlg.Dispose();
}

private System.Windows.Forms.Button button1;
private System.Windows.Forms.PictureBox pictureBox1;

}
}

Form1.cs

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;

namespace MyForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace MyForm
{
static class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

No comments: