Home VB.NET 1 VB.NET 2 VB.NET 3 VB.NET 4 VB.NET 5 VB.NET 6 VB.NET 7 VB.NET 8 VB.NET 9 VB.NET 10 VB.NET 11 VB.NET 12 VB.NET 13 VB.NET 14 VB.NET 15 VB.NET 16 VB.NET 17 About

VB.NET 6

Code, Design and Applications


DIALOG BOXES

Lets code the three different kinds of dialog boxes using coding technique, no drag and drop of controls!

THE CODE

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim OpenDialogAdd As New OpenFileDialog()

OpenDialogAdd.FileName = ""

OpenDialogAdd.Filter = "Web Files |*.htm; *.html| Text Files | *.txt| VStudio |*.vb; *.cs| All Files| *.*"

OpenDialogAdd.InitialDirectory = "C:\"

OpenDialogAdd.ShowDialog()

Dim sFile As String = ""

If OpenDialogAdd.CheckFileExists And (OpenDialogAdd.FileName <> "") Then

  'NotepadFilename = OpenDialogAdd.FileName

  'RichTextBox1.LoadFile(OpenDialogAdd.FileName, RichTextBoxStreamType.PlainText)

End If

End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Try

  Dim saveDialog As New SaveFileDialog()

  'saveDialog.FileName = NotepadFilename

  saveDialog.Filter = "All Files| *.*"

  saveDialog.InitialDirectory = "C:\"

  saveDialog.ShowDialog()

  Dim sFile As String = ""

  If saveDialog.FileName <> "" Then

    'RichTextBox1.SaveFile(saveDialog.FileName)

    'NotepadFilename = "C:\ShellCities\Programs\Notepad\" & saveDialog.FileName

  End If

Catch ex As Exception


End Try

End Sub


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim BrowseDialog As New FolderBrowserDialog

BrowseDialog.ShowDialog()


If (BrowseDialog.SelectedPath IsNot Nothing) Then

'TextBox1.text = BrowseDialog.SelectedPath

End If

End Sub

End Class