C# Open File Dialog
What Is It:
It does what it says, it opens a file!
Getting Started:
Begin by making a button, a picturebox, and an OpenFileDialog.
Double Click the button and insert the following.
Code
string File = "";
openFileDialog1.Title = "HackForums";
openFileDialog1.InitialDirectory = "C:";
openFileDialog1.Filter = "JPEG|*.jpg";
openFileDialog1.ShowDialog();
File = openFileDialog1.FileName;
pictureBox1.Image = Image.FromFile(File);string File = "";
Creates a string variable with no text.
openFileDialog1.Title = "HackForums";
openFileDialog1.InitialDirectory = "C:";
openFileDialog1.Filter = "JPEG|*.jpg";
The first line sets the title on top of the box.
The second line sets the directory it will begin searching in.
The third line sets the filter, the dialog will only except jpeg picture files.
Underneath that insert this:
Code
openFileDialog1.ShowDialog();
File = openFileDialog1.FileName;
pictureBox1.Image = Image.FromFile(File);The first line shows the Dialog.
The second line says that the previous empty string is now the name of the file you open.
The third line sets your picture box equal to the picture file you just opened!
Spoiler (Click to View)
Final Code:
Code
private void button1_Click(object sender, EventArgs e)
{
string File = "";
openFileDialog1.Title = "HackForums";
openFileDialog1.InitialDirectory = "C:";
openFileDialog1.Filter = "JPEG|*.jpg";
openFileDialog1.ShowDialog();
File = openFileDialog1.FileName;
pictureBox1.Image = Image.FromFile(File);
}http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.


