Pages

Sunday 14 October 2012

Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Description:
In this post we are going to learn the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Open Microsoft visual studio
File-> New -> Project -> visual vb -> Windows Forms Application.

Program:
Take 6 button on the top.
now drag and drop all five dialog OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog on the form it will automatically go to bellow as shown in figure.



Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.
Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.



take text field and PictureBox as shown in figure.

now double click on all button turn by turn and paste the code as shown in below. 


Public Class Form1

    Private Sub btnopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click
        OpenFileDialog1.Title = "open"
        OpenFileDialog1.InitialDirectory = "D:\"
        If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
            PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
        End If
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        SaveFileDialog1.Title = "Save As"
        SaveFileDialog1.Filter = "TXT Files (*.txt*)|*.txt*"
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text, True)

        End If

    End Sub

    Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click
        FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
        FolderBrowserDialog1.SelectedPath = "D:\"
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub btnfont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfont.Click
        If FontDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            TextBox1.Font = FontDialog1.Font
            TextBox1.ForeColor = FontDialog1.Color
        End If
    End Sub

    Private Sub btncolor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncolor.Click
        If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            TextBox1.BackColor = ColorDialog1.Color
        End If
    End Sub

    Private Sub btnuser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuser.Click
        Dim frm As Form2 = New Form2
        frm.TextBox1.Text = Me.TextBox1.Text
        frm.ShowDialog()
    End Sub
End Class


No comments:

Post a Comment