OpenFileDialog Question
I have the following code written for the opening of a BMP image from the File...Open on my menustrip.
Private
Sub OpenToolStripMenuItem_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles OpenToolStripMenuItem.ClickOpenFileDialog1.Filter =
"Image Files (*.bmp)|*.bmp"If OpenFileDialog1.ShowDialog() = DialogResult.OKThenDim fileNameAs [String] = OpenFileDialog1.FileNameEndIfEndSubI tryed it out and it worked, but i have a small question.....How can i change the default name that appears in the file name of the window browser? It is set to "OpenFileDialog1" How can i change it to an empty space?
EDIT: I just added a picturebox to display the image, i got it to load properly, but how can i change it so that the picture will resize to the size of the picturebox? Large Pictures often have pieces cut off.
To change the presented file name simply change the FileName property of your OpenFileDialog to an empty string before displaying the dialog.
As for resizing the image in the PictureBox, change the PictureBox's SizeMode property to PictureBoxSizeMode.Zoom to have the image be displayed no larger than the space available and to scale up and/or down as needed
You can set the default file name to empty by doing this:
OpenFileDialog1.FileName = ""
You can resize the image to the dialg by setting the picture box's SizeMode property to StretchImage.
-Scott Wisniewski
MS VB Compiler Dev
You should try clearing out the FileName in your dialog prior to the call to ShowDialog:
OpenFileDialog1.FileName = String.Empty
To change the sizing options of your picture box, you should try playing with SizeMode property of your picture box.
I assume you talking about the filename field in the dialog.
Set the filename prior to displaying the dialog, chnaging to a empty space - I assume you mean no file set (.FileName = "")
Dim o As New OpenFileDialog
With o
.Filter = "Image Files (*.bmp)|*.bmp"
.Title = "Open Bitmap File"
.FileName = "test.bmp" '//This will set it to a default value
If .ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fileName As [String] = .FileName
End If
End With
This dialog can be used for opening files.
The content is shown in textbox.
//using System.Data;
//using System.IO ;string fileName;OpenFileDialog OpenFile =
new OpenFileDialog();try {
OpenFile.CheckFileExists =
true;OpenFile.CheckPathExists =
true;OpenFile.DefaultExt = "txt";
OpenFile.DereferenceLinks =
true;OpenFile.Filter = "Text files (*.txt)|*.txt|" + "RTF files (*.rtf)|*.rtf|" +
"Word Documents (*.doc)|*.doc|" + "Works 6 and 7 (*.wps)|*.wps|" +
"Windows Write (*.wri)|*.wri|" + "WordPerfect document (*.wpd)|*.wpd";
OpenFile.Multiselect =
false;OpenFile.RestoreDirectory =
true;OpenFile.ShowHelp =
true;OpenFile.ShowReadOnly =
false;OpenFile.Title = "Select a file to convert";
OpenFile.ValidateNames =
true;if (OpenFile.ShowDialog() == DialogResult.OK){
fileName = OpenFile.FileName;
StreamReader sr =
new StreamReader(OpenFile.OpenFile());txtBox.Text = sr.ReadToEnd();
}
}
catch{
MessageBox.Show("Something is wrong here", "Text2Audio");
}
finally{
}