利用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
相關參考

留言

這個網誌中的熱門文章

開啟cshtml檔案時,出現『並未將物件參考設定為物件執行個體』的錯誤訊息

無法設定中斷點 尚未載入符號檔

DataGridView欄位計算總合