也看看是否有人可以回答我的另一个问题..
答案 0 :(得分:0)
不,就我所知,没有简单的方法可以像这样放大。特别是字体具有固定的方面,因此如果您正在任意调整表单大小,则不能轻易地使它们比正常更高或更宽。
然而,你可以强制调整大小以保持其宽高比,然后你可以递归地遍历所有控件,识别它们的类型,并在表单的Resize事件中适当地缩放它们 - 即:
Public Class Form1
Private lblSize As Single
Private Fwid As Integer
Private Fheight As Integer
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Me.Height = Fheight * Me.Width / Fwid
For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
Dim lbl As Label = DirectCast(ctl, Label)
Dim nFont As New Font(FontFamily.GenericSansSerif, lblSize * Me.Width / Fwid, FontStyle.Regular, GraphicsUnit.Point)
lbl.Font = nFont
End If
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Fwid = Me.Width
Fheight = Me.Height
lblSize = Label1.Font.Size
End Sub
End Class
您必须为您使用的每种控件类型执行此操作。我这里只做了字体大小,但你也必须缩放位置等。重新绘制它不会很漂亮,但它会起作用。一个更好的选择可能是与WPF一起使用,它有更多可用于执行此类操作的工具。
此外,如果您在控件(标签页,分组框等)中有控件,则必须使用递归来查找所有控件 - 例如:
Public Shared Function GetAllControlsRecurs(ByVal list As List(Of Control), ByVal parent As Control, ByVal ctrlType As System.Type) As List(Of Control)
If Parent Is Nothing Then Return list
If Parent.GetType Is ctrlType Then
list.Add(Parent)
End If
For Each child As Control In Parent.Controls
GetAllControlsRecurs(list, child, ctrlType)
Next
Return list
End Function
您将使用上述功能:
Dim buttonList As New List(Of Control)
Dim checkboxList As New List(Of Control)
'etc...
For Each ctl As Button In GetAllControlsRecurs(buttonList, Me, GetType(Button))
' Do something...
Next
For Each ctl As CheckBox In GetAllControlsRecurs(checkboxList, Me, GetType(CheckBox))
' Do Something...
Next
另外 - 接受答案可能会鼓励人们帮助你。