Dialogs in Visual Basic

The code for the OpenFileDialog is slightly more complicated. Before showing the dialog, we must set the filter. The filter consists of a description of the file type followed by the pipe | (the straight bar that is above the backslash) then the patern for the file type, then another pipe, etc.for as many file types as we want to allow.

The filter "Bitmaps|*.bmp|All files|*.*" lets the user select either Bitmaps or all files. The pattern for bitmaps is *.bmp.

8. After the file is selected, the FromFile function can be used to open a picture file.

Write the code as shown below:

    Private Sub BtnPicture_Click(sender As Object, e As EventArgs) Handles BtnPicture.Click
        Me.OpenFileDialog1.Filter = "Bitmaps|*.bmp|GIFS|*.gif|PNG|*.png|All files|*.*"
        Me.Pic1.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
    End Sub

Experiment: Add an input box to let the user change the greeting.

Experiment: After the font changes, or the greeting changes, or the size of the form changes, center the greeting. After the picture changes, or when the form changes size, center the picture.

NEXT: Loops in Visual Basic