FILE DIALOG
Open
File Dialog merupakan jendela atau form dialog yang digunakan untuk mendapatkan
suatu lokasi sebuah atau lebih file, pada form tersebut file file yang terlihat
dapat di filter agar file dengan ekstensi tertentu yang terlihat saja.
Save
File Dialog merupakan jendela atau form dialog yang digunakan untuk mengeset
lokasi suatu file yang telah kita buat untuk disimpan ke dalam suatu disk.
Tutorial : Menyimpan Inputan ke dalam file .TXT
- Langkah pertama adalah buka program microsoft visual studio 2008 dengan cara klik Start > All program > Microsoft Visual Studio 2008.
- Langkah Kedua klik pada create project untuk memulai project baru, atau masuk ke menu File > New Project.
- Langkah ketiga pilih Windows Forms Application, anda bisa merubah nama project anda pada textbox di bagian bawah. Klik OK.
- Langkah keempat buatlah desain MDI form Main Menu, form Meter To English, dan form Inches To Metrics seperti gambar di bawah ini. Lalu ubahlah propertiesnya seperti pada tabel berikut:
Objek
|
Text
|
Name
|
Form1
|
Contoh
|
FileDialog
|
Picture
Box
|
picFoto
|
|
Button1
|
Buka File
|
btnBuka
|
Button2
|
Report
|
btnReport
|
Button3
|
Simpan
|
btnSimpan
|
ComboBox
|
cmbFormat
|
|
OpenFileDialog1
|
||
SaveFileDialog1
|
Form 1
Objek
|
Text
|
Name
|
Form2
|
Report
|
frmReport
|
PrintPreviewControl1
|
||
PrintDocument1
|
Form Report
- Langkah kelima masukkan koding berikut:
1.Form Contoh
Public Class FileDialog
Private Sub btnBuka_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuka.Click
OpenFileDialog1.Filter = "JPEG|*.JPG|BITMAP|*.BMP|GIF|*.GIF|ICON|*.ICO"
OpenFileDialog1.RestoreDirectory = True
OpenFileDialog1.ShowDialog()
picFoto.SizeMode = PictureBoxSizeMode.StretchImage
picFoto.ImageLocation = OpenFileDialog1.FileName
End Sub
Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
frmReport.Show()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
Dim Gambar As New System.Drawing.Bitmap(picFoto.Image)
SaveFileDialog1.ShowDialog()
Dim Lokasi As String = SaveFileDialog1.FileName() + Microsoft.VisualBasic.Right(OpenFileDialog1.FileName, 4)
Lokasi = Microsoft.VisualBasic.Replace(UCase(Lokasi), _
Microsoft.VisualBasic.Right( _
UCase(OpenFileDialog1.FileName), 4), _
"." & cmbFormat.Text & "")
Gambar.Save(Lokasi, System.Drawing.Imaging.ImageFormat.Bmp)
MsgBox("Penyimpanan Sukses!")
End Sub
Private Sub FileDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbFormat.Items.Add("JPEG")
cmbFormat.Items.Add("BMP")
cmbFormat.Items.Add("GIF")
End Sub
End Class
view plainprint?
2.Form Report
Public Class frmReport
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim ReportFont As Font = New Drawing.Font("Times New Roman", 48)
Dim ReportBodyFont As Font = New Drawing.Font("Times New Roman", 48)
e.Graphics.DrawString("my example report title", ReportFont, Brushes.Chocolate, 100, 100)
e.Graphics.DrawString("the body of my report", ReportBodyFont, Brushes.CornflowerBlue, 100, 125)
End Sub
Private Sub frmReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PrintPreviewControl1.Document = PrintDocument1
End Sub
End Class
- Langkah keenam untuk mendapatkan hasil dari coding di atas kita tekan F5 pada keyboard anda, maka hasilnya akan seperti berikut.
- Langkah ketujuh, jika telah selesai klik tombol exit untuk mengakhiri aplikasi.
Tutorial : Menyimpan Inputan ke dalam file .TXT
- Langkah pertama adalah buka program microsoft visual studio 2008 dengan cara klik Start > All program > Microsoft Visual Studio 2008.
- Langkah Kedua klik pada create project untuk memulai project baru, atau masuk ke menu File > New Project.
- Langkah ketiga pilih Windows Forms Application, anda bisa merubah nama project anda pada textbox di bagian bawah. Klik OK.
- Langkah keempat buatlah seperti gambar di bawah ini. Lalu ubahlah propertiesnya seperti pada tabel berikut:
Objek
|
Text
|
Name
|
GroupBox1
|
Enter Data
Karyawan
|
|
Label1
|
First Name
|
|
Label2
|
Middle Name
|
|
Label3
|
Last Name
|
|
Label4
|
Employee
Number
|
|
Label5
|
Department
|
|
Label6
|
Telephone
|
|
Label7
|
Email
Address
|
|
TextBox1
|
txtFirstName
|
|
TextBox2
|
txtMiddleName
|
|
TextBox3
|
txtLastName
|
|
TextBox4
|
txtEmployeeNumber
|
|
ComboBox
|
cmbDepartment
|
|
TextBox5
|
txtTelephone
|
|
TextBox6
|
txtEmail
|
|
SaveFileDialog1
|
||
Button1
|
Save
|
btnSave
|
Button2
|
Clear
|
btnClear
|
Button3
|
Exit
|
btnExit
|
- Langkah kelima masukkan koding berikut
Public Class SimpanData
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InputBox("Enter File Name:")
cmbDepartment.Items.Add("Accounting")
cmbDepartment.Items.Add("Administration")
cmbDepartment.Items.Add("Receptionist")
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim i As Integer = FreeFile()
FileOpen(i, "F:\Data.txt", OpenMode.Output)
PrintLine(i, txtFirstName.Text, txtMiddleName.Text, txtLastName.Text, txtEmployeeNumber.Text, _
cmbDepartment.SelectedItem, txtTelephone.Text, txtEmail.Text)
FileClose(i)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFirstName.Clear()
txtMiddleName.Clear()
txtLastName.Clear()
txtEmployeeNumber.Clear()
cmbDepartment.ResetText()
txtTelephone.Clear()
txtEmail.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Dim t = MsgBox("Simpan Data?", MsgBoxStyle.YesNo)
If t = MsgBoxResult.Yes Then
Me.Close()
Else
Me.Close()
End If
End Sub
End Class
- Langkah keenam untuk mendapatkan hasil dari coding di atas kita tekan F5 pada keyboard anda, maka hasilnya akan seperti berikut.
- Langkah ketujuh, jika telah selesai klik tombol exit untuk mengakhiri aplikasi.