0
是否有一種簡單/快速的方法來更改VB.net應用程序中所有控件的字體? (目前使用VB 2015)VB.net VS2015更改整個項目的字體
我的意思是所有的文本框,按鈕等。它應該是獨立的系統 默認字體。
在整個項目(30-40表格+)中更改每個控件將極其耗費人力。
是否有一種簡單/快速的方法來更改VB.net應用程序中所有控件的字體? (目前使用VB 2015)VB.net VS2015更改整個項目的字體
我的意思是所有的文本框,按鈕等。它應該是獨立的系統 默認字體。
在整個項目(30-40表格+)中更改每個控件將極其耗費人力。
即使我猜測它不建議更改默認字體的家庭;有時需要它,特別是對於可訪問性,定製和個性化。這也可以爲其他應用程序中的最終用戶提供很好的功能。
感謝許多帖子和答案,並將它們結合起來;你可以嘗試 在運行時更改整個項目的字體系列。
步驟自定義字體添加到VB.NET和WinForms :
Imports System.Drawing.Text
Public Class Form1
Dim pfc As New PrivateFontCollection()
Private Function FindALLControlRecursive(ByVal list As List(Of Control), ByVal parent As Control) As List(Of Control)
' function that returns all control in a form, parent or child regardless of control's type
If parent Is Nothing Then
Return list
Else
list.Add(parent)
End If
For Each child As Control In parent.Controls
FindALLControlRecursive(list, child)
Next
Return list
End Functio
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
' On Form1 shown, start applying font
Dim CFontPath As String = Application.StartupPath
pfc.AddFontFile(CFontPath & "\Resources\Fonts\Roboto.ttf")
Dim allCtrl As New List(Of Control)
For Each ctrl As Control In FindALLControlRecursive(allCtrl, Me)
' You need to define which control type to change it's font family; not recommendd to just change all controls' fonts, it will create a missy shape
If TypeOf ctrl Is Label Or TypeOf ctrl Is TextBox Or TypeOf ctrl Is Button Or TypeOf ctrl Is CheckBox Or TypeOf ctrl Is RadioButton Or TypeOf ctrl Is ProgressBar Or TypeOf ctrl Is GroupBox Or TypeOf ctrl Is Chart Then
Dim CurrentCtrlFontSize = ctrl.Font.Size ' get current object's font size before applying new font family
ctrl.Font = New Font(pfc.Families(0), CurrentCtrlFontSize, FontStyle.Regular)
End If
Next
allCtrl.Clear()
End Sub
End Class
我不能肯定儘管這是最優的代碼或最好的方法,但它做的工作,並希望一些合作。
我知道它的一箇舊的日期問題,但希望這個答案有幫助和它非常有趣的問題。
顯然編輯窗體設計器中的文件是可能的,但印象中的IM你應該做的:) – Josh
寫一個應用程序來做到這一點,你可以通過設計文件,並替換所有字體屬性... – Codexer
沒有什麼內置VS來做到這一點。你可以寫一個VS擴展,然後這將是你想要的快速和簡單的操作。 – jmcilhinney