How do you make an open file dialog?
Posted: Sat May 26, 2007 6:34 pm
Sorry but i really need to know. Im trying to make a resigner.
Visit remnantmods.com for more information
http://www.halomods.info/
Code: Select all
OpenFileDialog OFD = new OpenFileDialog();
OFD.Filter = "Map(*.map)|*.map";
OFD.FilterIndex = 1;
if (OFD.ShowDialog() == DialogResult.OK)
{
// Load the contents of the .map file here.
}
Code: Select all
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
' Show the open file dialogue box.
If ofdSelectPicture.ShowDialog = Windows.Forms.DialogResult.OK Then
' Load the picture in the picture box.
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName)
' show the name of the file's location in a text box
txtDestination.Text = "" & ofdSelectPicture.FileName
End If
End Sub
Code: Select all
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
' Show the open file dialogue box.
If ofdSelectPicture.ShowDialog = Windows.Forms.DialogResult.OK
End Sub
Code: Select all
Dim ofd As New OpenFileDialog
ofd.Filter = "Halo 2 Maps|*.map"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
'code for pressing ok here
End If
sorry if it was unfinished, but I copied that from my app where it worked fineLuxuriousMeat wrote:Why are giving him unfinished code?
To make it easy just use this:Code: Select all
Dim ofd As New OpenFileDialog ofd.Filter = "Halo 2 Maps|*.map" If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then 'code for pressing ok here End If
that is finished...Patrickh wrote:sorry if it was unfinished, but I copied that from my app where it worked fineLuxuriousMeat wrote:Why are giving him unfinished code?
To make it easy just use this:Code: Select all
Dim ofd As New OpenFileDialog ofd.Filter = "Halo 2 Maps|*.map" If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then 'code for pressing ok here End If
Thats the code I posted, he had no End If.halo0001 wrote:that is finished...Patrickh wrote:sorry if it was unfinished, but I copied that from my app where it worked fineLuxuriousMeat wrote:Why are giving him unfinished code?
To make it easy just use this:Code: Select all
Dim ofd As New OpenFileDialog ofd.Filter = "Halo 2 Maps|*.map" If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then 'code for pressing ok here End If
Code: Select all
/* Once the using statement has finished, the garbage
* collector knows to dispose of the ofd straight away */
using (OpenFileDialog o = new OpenFileDialog())
{
//Set some properties
o.Title = "Open File Dialog";
o.Filter = "All Files (*.*)|*.*";
if (o.ShowDialog() != DialogResult.Cancel)
{
// The user has selected a file
}
else
{
// Cancel was pressed
}
}
I understand that all, but what does that do, just dispose it when you're finished or what? I used to use it when I used vb.net, but stopped.Prey wrote:If your going to create an openfiledialog on the fly, you might as well in-close it in a using statement.
Code: Select all
/* Once the using statement has finished, the garbage * collector knows to dispose of the ofd straight away */ using (OpenFileDialog o = new OpenFileDialog()) { //Set some properties o.Title = "Open File Dialog"; o.Filter = "All Files (*.*)|*.*"; if (o.ShowDialog() != DialogResult.Cancel) { // The user has selected a file } else { // Cancel was pressed } }