你可以使用Extension方法做这样的事情.
Imports System.Runtime.CompilerServices
Module FontExtensions
<Extension()> Public Function ToSize(ByVal OriginalFont As Font, ByVal NewSize As Single) As Font
Dim NewFont As Font
NewFont = New Font(OriginalFont.FontFamily, NewSize, OriginalFont.Style)
Return NewFont
End Function
End Module
Run Code Online (Sandbox Code Playgroud)
然后像这样称呼它......
SomeObject.Font = Font.ToSize(12)
Run Code Online (Sandbox Code Playgroud)
它仍在幕后创建一个新字体,但您的应用程序代码不会与创建过程混杂在一起.