Pages

Monday, August 8, 2011

"Browse..." button in Windows forms

Since there is no such "Browse..." button in Windows forms, I created something equivalent using the following method:

Add a button control and set the text as "Browse...".
In the button click event,

OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory =  "c:\\";

openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)

if ((myStream = openFileDialog1.OpenFile()) != null)                           
 txt_FilePath.Text = openFileDialog1.FileName;
 myStream.Close();

Then add a text box control(txt_FilePath) infront of the button and set the text property to file path.

No comments:

Post a Comment