5 Replies - 8358 Views - Last Post: 01 September 2009 - 09:37 PM Rate Topic: -----

#1 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

How to make a open file dialog for a textbox

Post icon  Posted 01 September 2009 - 07:26 PM

'Set the Open dialog properties
With OpenFileDialog1
		.Filter = "Text Documents (*.txt) |*.txt|All Files (*.*)|*.*"
		.Filterindex = 1
		.Title = "Open File'
End With

'Show the Open dialog and if the user clicks the Open button,
'load the file
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Ok Then
	Try
		  'Save the file path and name
		  strFileName = openFileDialog1.FileName

	Catch ex As Exception
			MessageBox.Show(ex.Message, My.Application.Info.Title, _
				   MessageBoxButtons.OK, MessageBoxIcon.Error)
	End Try
		  End If


Is This A Good Question/Topic? 0
  • +

Replies To: How to make a open file dialog for a textbox

#2 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: How to make a open file dialog for a textbox

Post icon  Posted 01 September 2009 - 07:29 PM

'Set the Save dialog properties
		With SaveFileDialog1
			.DefaultExt = "txt"
			.FileName = strFileName
			.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
			.FilterIndex = 1
			.OverwritePrompt = True
			.Title = "Save File"
		End With

		'Show the Save dialog and if the user clicks the Save button,
		'save the file
		If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
			Try
				'Save the file path and name
				strFileName = SaveFileDialog1.FileName

				My.Computer.FileSystem.WriteAllText(strFileName, TextBox1.Text, False)
			Catch ex As Exception
				MessageBox.Show(ex.Message, My.Application.Info.Title, _
					MessageBoxButtons.OK, MessageBoxIcon.Error)
			End Try
		End If

Was This Post Helpful? 0
  • +
  • -

#3 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: How to make a open file dialog for a textbox

Post icon  Posted 01 September 2009 - 07:31 PM

'Set the Save dialog properties
		With SaveFileDialog1
			.DefaultExt = "txt"
			.FileName = strFileName
			.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
			.FilterIndex = 1
			.OverwritePrompt = True
			.Title = "Save File"
		End With

		'Show the Save dialog and if the user clicks the Save button,
		'save the file
		If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
			Try
				'Save the file path and name
				strFileName = SaveFileDialog1.FileName

				My.Computer.FileSystem.WriteAllText(strFileName, TextBox1.Text, False)
			Catch ex As Exception
				MessageBox.Show(ex.Message, My.Application.Info.Title, _
					MessageBoxButtons.OK, MessageBoxIcon.Error)
			End Try
		End If

Was This Post Helpful? 0
  • +
  • -

#4 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: How to make a open file dialog for a textbox

Post icon  Posted 01 September 2009 - 07:33 PM

		'Set the Font dialog properties
		FontDialog1.ShowColor = True

		'Show the Font dialog and if the user clicks the OK button,
		'update the font and color in the text box
		If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
			txtFile.Font = FontDialog1.Font
			txtFile.ForeColor = FontDialog1.Color
		End If

Was This Post Helpful? 0
  • +
  • -

#5 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: How to make a open file dialog for a textbox

Post icon  Posted 01 September 2009 - 07:35 PM

		'Show the Color dialog and if the user clicks the OK button,
		'update the background color of the form
		If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
			Me.BackColor = ColorDialog1.Color
		End If

Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,105
  • Joined: 07-September 06

Re: How to make a open file dialog for a textbox

Posted 01 September 2009 - 09:37 PM

Moved to VB.Net.

Please don't post multiple threads on the same topic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1