所以我一直在用这段代码来改变字体属性
Me.lblOutPut.Font = New Font("Times New Roman", 22)
但是,我在我的程序中有选项来更改字体大小和字体类型,如果我必须更改字体大小,例如,我必须在代码中指定字体类型。有没有办法创建可以动态改变字体大小和样式的变量?
例如,因为我认为我还没有说清楚自己:
12
更改为16
Me.lblOutPut.Font = New Font("Times New Roman", 16)
Me.lblOutPut.Font = New Font("Arial", 12)
如何使字体大小不变,但字体类型呢?
答案 0 :(得分:0)
我认为你需要这样的东西:
Private Function setFont(myFont As Font, Optional fontFamily As String = "", Optional fontSize As Single = 0) As Font
If fontFamily = "" Then
fontFamily = myFont.FontFamily.ToString()
End If
If fontSize = 0 Then
fontSize = myFont.Size
End If
Return New Font(fontFamily, fontSize)
End Function
你可以像这样使用它:
' To change both FontFamily And Size
Me.lblOutPut.Font = setFont(Me.lblOutPut.Font, "Times New Roman", 16)
' To change only FontFamily
Me.lblOutPut.Font = setFont(Me.lblOutPut.Font, "Times New Roman", 0)
' Or
Me.lblOutPut.Font = setFont(Me.lblOutPut.Font, "Times New Roman")
' To change only Size
Me.lblOutPut.Font = setFont(Me.lblOutPut.Font, "", 12)