- MessageBox
- OpenFileDialog
- SaveFileDialog
- FontDialog
- ColorDialog
- InputBox
MessageBox Code:
Public Class Form1
'sets the new variable strName
Dim strName As String
Dim strName As String
Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
'sets TextBox1.Text's property to the string strName
strName = TextBox1.Text
'display's a messagebox with the strName variable.
MsgBox("The text you entered is: " & strName, MessageBoxIcon.Exclamation, strName)
End Sub
End Class
OpenFileDialog Code:
Public Class Form1
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
'declare the OpenFileDialog & set it's properties
Dim ofd As New OpenFileDialog
ofd.InitialDirectory = "C:\"
ofd.Filter = "JPG (.jpg)|*.jpg"
ofd.Title = "Choose An Image File..."
'sets PictureBox1's image to OpenFileDialog's file
If ofd.ShowDialog = DialogResult.OK Then
PictureBox1.ImageLocation = ofd.FileName
End If
End Sub
End Class
Public Class Form1
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
'declare the OpenFileDialog & set it's properties
Dim ofd As New OpenFileDialog
ofd.InitialDirectory = "C:\"
ofd.Filter = "JPG (.jpg)|*.jpg"
ofd.Title = "Choose An Image File..."
'sets PictureBox1's image to OpenFileDialog's file
If ofd.ShowDialog = DialogResult.OK Then
PictureBox1.ImageLocation = ofd.FileName
End If
End Sub
End Class
SaveDialog Code:
Public Class Form1
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'declare a SaveFileDialog and set it's properties
Dim sfd As New SaveFileDialog
sfd.InitialDirectory = "C:\"
sfd.Filter = "JPG (.jpg)|*.jpg"
sfd.Title = "Choose An Location..."
'shows a messagebox with the SaveFileDialog's filename
If sfd.ShowDialog = DialogResult.OK Then
MsgBox("You saved your file in this location: " & sfd.FileName)
End If
End Sub
End Class
FontDialog Code:
Public Class Form1
Private Sub btnFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFont.Click
'declare the FontDialog
Dim fd As New FontDialog
'changes lblFont's font to fd's font
If fd.ShowDialog = DialogResult.OK Then
lblFont.Font = fd.Font
End If
End Sub
End Class
Public Class Form1
Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click
'declare the ColorDialog
Dim cd As New ColorDialog
'changes lblColor's ForeColor to cd's color
If cd.ShowDialog = DialogResult.OK Then
lblColor.ForeColor = cd.Color
End If
End Sub
End Class
InputBox Code:
Public Class Form1
Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
'declare the InputBox as a string (strName)
Dim strName As String = InputBox("Enter your name:",
"Your Name")
'show a messagebox with strName
MsgBox("Your name is: " & strName, MessageBoxIcon.Exclamation, strName)
End Sub
End Class
No comments:
Post a Comment