Use With statement with OpenFileDialog : With statement « Statements « VB.Net Tutorial






Imports System.Windows.Forms

public class OpenFileDialogWith
   public Shared Sub Main
        Dim OpenFileDialog1 As OpenFileDialog = New System.Windows.Forms.OpenFileDialog
        With OpenFileDialog1
            .FileName = "C:\My Documents\Doc1.txt"
            .DefaultExt = ".txt"
            .Filter = "Text Files|*.TXT"
            .Filter = "Bitmaps|*.BMP|GIF Images|*.GIF|" & _
               "JPG Images|*.JPG|All Images|*.BMP;*.GIF;*.JPG"
            .FilterIndex = 2
            .InitialDirectory = "C:\My Documents"
            .ShowReadOnly = True
            .ReadOnlyChecked = True
        End With

        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Console.WriteLine(OpenFileDialog1.FileName)
            
        End If


   End Sub
End class








4.5.With statement
4.5.1.Use With statement with Form object
4.5.2.Insert statement into With statement
4.5.3.Nested With statement
4.5.4.Use With statement with OpenFileDialog