C# Source Codes: OpenFileDialog

Tuesday, January 12, 2010

OpenFileDialog







Source Code : 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 Open_File_Dialog
{
public partial class Form1 : Form
{
OpenFileDialog Browse;
public Form1()
{
InitializeComponent();

Browse = new OpenFileDialog();
Browse.Title = "Open your picture";
Browse.Filter = "|*.jpg;*.bmp;*.gif;*.png";
Browse.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
}

private void button1_Click(object sender, EventArgs e)
{
if (Browse.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox1.Image = Image.FromFile(Browse.FileName);
groupBox1.Text = Browse.FileName;
}
catch
{
MessageBox.Show("Cann't open !");
}
}
}
}
}




Source Code : Form1.Designer.cs

namespace Open_File_Dialog
{
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


private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.pictureBox1);
this.groupBox1.Location = new System.Drawing.Point(10, 6);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(373, 250);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "My Picture";
//
// button1
//
this.button1.Location = new System.Drawing.Point(125, 267);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 41);
this.button1.TabIndex = 1;
this.button1.Text = "Browse";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(6, 19);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(361, 225);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(395, 320);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = " Open File Dialog";
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.PictureBox pictureBox1;
}
}





Download :

exe
http://sites.google.com/site/ogremyfiles/OpenFileDialog_EXE.rar
Source Code
http://sites.google.com/site/ogremyfiles/OpenFileDialog_SourceCode.rar



Designed by : Ogre