Font Viewer ini hanya menggunakan beberapa Komponen dasar dari VB seperti Button, Textbox dan Listbox.
- Load semua font yang terinstal di Komputer ke LstFont
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim huruf As New InstalledFontCollection
For Each jns As FontFamily In huruf.Families
LstFont.Items.Add(jns.Name)
Next jns
End Sub
Dim huruf As New InstalledFontCollection
For Each jns As FontFamily In huruf.Families
LstFont.Items.Add(jns.Name)
Next jns
End Sub
- Buat Method untuk mengganti huruf yang sebelumnya
Public Sub Ganti()
Dim Size As Single = 12
Try
Size = Single.Parse(LstSize.SelectedItem)
Catch ex As Exception
End Try
Dim JnsHuruf As String = "Times New Roman"
Dim Style As FontStyle = FontStyle.Regular
If Not (LstFont.SelectedItem Is Nothing) Then
JnsHuruf = LstFont.SelectedItem.ToString
End If
If LstStyle.SelectedItem = "Bold" Then
Style = FontStyle.Bold
ElseIf LstStyle.SelectedItem = "Strike Out" Then
Style = FontStyle.Strikeout
ElseIf LstStyle.SelectedItem = "Italic" Then
Style = FontStyle.Italic
Else
Style = FontStyle.Regular
End If
Dim new_font As New Font(JnsHuruf, Size, Style)
TextContoh.Font = new_font
End Sub
Dim Size As Single = 12
Try
Size = Single.Parse(LstSize.SelectedItem)
Catch ex As Exception
End Try
Dim JnsHuruf As String = "Times New Roman"
Dim Style As FontStyle = FontStyle.Regular
If Not (LstFont.SelectedItem Is Nothing) Then
JnsHuruf = LstFont.SelectedItem.ToString
End If
If LstStyle.SelectedItem = "Bold" Then
Style = FontStyle.Bold
ElseIf LstStyle.SelectedItem = "Strike Out" Then
Style = FontStyle.Strikeout
ElseIf LstStyle.SelectedItem = "Italic" Then
Style = FontStyle.Italic
Else
Style = FontStyle.Regular
End If
Dim new_font As New Font(JnsHuruf, Size, Style)
TextContoh.Font = new_font
End Sub
- Mengganti Warna
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim warna As New ColorDialog
If warna.ShowDialog = Windows.Forms.DialogResult.OK Then
TextContoh.ForeColor = warna.Color
End If
End Sub
Dim warna As New ColorDialog
If warna.ShowDialog = Windows.Forms.DialogResult.OK Then
TextContoh.ForeColor = warna.Color
End If
End Sub
- Memanggil Method Ganti saat salah satu listbox di pilih
Private Sub LstFont_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstFont.SelectedIndexChanged, LstSize.SelectedIndexChanged, LstStyle.SelectedIndexChanged
Ganti()
End Sub
Ganti()
End Sub
Maaf saya mau nanya, pengen nampilkan warna yang sesuai dengan keinginan bisa nggak ?
BalasHapusmksdnya ketika di klik button color, cuman tampil warna-warna pilihan kita sendiri...
*Please sharenya scriptnya....
nich emailnya : novinaldi.jayanusa@yahoo.com
thank's before... ^_^