Hi @Simon
Please check if the following code helps.
Calculate the scaled font size in CalculateDesiredFontSize
, and then use judgments in ApplyFontSize
to limit the minimum font.
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
ApplyFontSize(TextBox1)
ApplyFontSize(Label1)
' Add more controls that need to have font size limited to 8 points
End Sub
Private Sub ApplyFontSize(control As Control)
Dim desiredFontSize As Single = CalculateDesiredFontSize()
If desiredFontSize < 8 Then
desiredFontSize = 8
End If
control.Font = New Font(control.Font.FontFamily, desiredFontSize, control.Font.Style)
End Sub
Private Function CalculateDesiredFontSize() As Single
' Adjust the calculation based on your desired logic
Dim desiredFontSize As Single = Me.ClientSize.Width * 0.02
Return desiredFontSize
End Function
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.