Rabu, 14 November 2012

Using OpenFileDialog, ColorDialog, FontDialog & SaveFileDialog VB 2010



¨       Buat project baru dengan cara File-> New Project
¨       Berinama project  sesuka anda
Buat rancangan form seperti gambar di bawah ini;

Tabel Property Object


¨      

¨       Double klik pada tombol Open Image, ketikkan kode program berikut;

        With OpenFileDialog1
.Filter = "Picture Files (*.BMP; *.GIF; *.JPG)|*.BMP;*.GIF;*.JPG|Bitmap Files (*.BMP)|*.BMP|GIF Files (*.GIF)|*.GIF|JPEG Files (*.JPG)|*.JPG|All FIles (*.*)|*.*"
            .ShowDialog()
            PictureBox1.ImageLocation = .FileName
        End With

¨       Double klik pada tombol OpenAudio, ketikkan kode program berikut;

        Dim file As String
        With OpenFileDialog1
 .Filter = "All Support|*.mp3;*.wav;*.mid;*.wma;*.dat;*.avi;*.wmv;*.mpeg;*.mpg|mp3 files|*.mp3|all files|*.*"

            .Multiselect = True
            If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                For Each file In OpenFileDialog1.FileNames
                    ListBox1.Items.Add(file)
                Next
            End If
        End With

¨       Double klik pada tombol Color Dialog, ketikkan kode program berikut;

 ColorDialog1.ShowDialog()
        ListBox1.BackColor = ColorDialog1.Color

¨       Double klik pada tombol Font Dialog, ketikkan kode program berikut;

 FontDialog1.ShowDialog()
        LbTest.Font = FontDialog1.Font




¨       Double klik pada tombol Save As Img, ketikkan kode program berikut;

        Dim sPath As String
        Dim bmp As Bitmap

        SaveFileDialog1.Filter = "Bitmap image (*.bmp)|*.bmp"
        SaveFileDialog1.ShowDialog()
        sPath = SaveFileDialog1.FileName

        Try
            bmp = Me.PictureBox1.Image
            bmp.Save(sPath)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

¨       Double klik pada tombol Input Box, ketikkan kode program berikut;

 Dim strUserInput As String
 strUserInput = InputBox("Enter your Name:", "Name of Client")
        LbTest.Text = strUserInput




         Tekan tombol F5/Run untuk melihat hasilnya




Download : Sample Project
Download : Tutrial Dasar Visual Basic 2010

1 komentar: