OpenFileDialog Question

I have the following code written for the opening of a BMP image from the File...Open on my menustrip.

PrivateSub OpenToolStripMenuItem_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles OpenToolStripMenuItem.Click

OpenFileDialog1.Filter ="Image Files (*.bmp)|*.bmp"

If OpenFileDialog1.ShowDialog() = DialogResult.OKThen

Dim fileNameAs [String] = OpenFileDialog1.FileName

EndIf

EndSub

I 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.

[2257 byte] By [NewProgrammer] at [2007-12-22]
# 1

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

BrendanGrant at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Grrr... sorry about the dupes, something on the forums seems to be broken again... I reply and it is displayed as part of the thread. I refresh the page and it is gone. I repost and it shows two replies. I delete one and both are gone.

BrendanGrant at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

try:

theOpenFileDialog.FileName= ""

of course replacing the control variable name

does this help?

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
NewProgrammer wrote:

I 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.

ofd.Title = "open"

Me.PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize

DMan1 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

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

scottwis_MS at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

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.

MWade_MS at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7

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

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8
fast responses and a lot of them. thank you, problem solved.
NewProgrammer at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 9

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

{

}

R_S_Chandrashekar at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...