利用Combobox來選擇字型
Note:.net framework 2.0 , Windows Form
一般在使用Word之類的文書編輯軟體時在選擇字體的時候,可以在Combobox裡面看到字體的樣式,那在程式裡面怎麼做呢?下面我們來看看完成圖以及程式碼
不過這程式還有些問題,有些字型沒有辦法描繪,還沒有去找問題,先用try..catch去避開,參考看看嚕
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.DrawMode = DrawMode.OwnerDrawVariable
Dim oneFontFamily As FontFamily
For Each oneFontFamily In FontFamily.Families
ComboBox1.Items.Add(oneFontFamily.Name)
Next
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
Dim g As Graphics = e.Graphics
Try
g.DrawString(ComboBox1.Items.Item(e.Index), _
New Font(ComboBox1.Items.Item(e.Index).ToString, 10), _
Brushes.Black, e.Bounds.X, e.Bounds.Y)
Catch ex As Exception
End Try
End Sub
相關參考