There are 3 ways to do it :
1st : You customize each of your controls to make it able to fit it's Fontsize to the Controls dimension
2nd : You customize your Container-Control to do the same with the Controls belonging to it
3rd : You add a method to your Form (which is also a Container) to do that with the Controls belonging to it.
Now you should decide if you want to have the maximum Fontsize for each of those Controls (one Control has Fontsize=16 and one has 12 and so on) ... OR ... if you want to have the maximum Fontsize which is common to the Controls (one Control has Fontsize=16 and one has 12 - so you set each to 12).
The way to realize it is :
- iterate to the Controls-Collection of your Container
- get the Size of each Control and it's Text-Content and calculate the maximum possible Fontsize of this Control and memorize it (depending on your decision)
- ::
- iterate to the Controls-Collection of your Container
- set the Size of each Control to the new (calculated) Fontsize
Here is a method to get the maximum matching Fontsize for a given Size of a Control depending on it's Text-Content and the selected Font and it's Style :
Function GetFontSizeMatch(ByVal myText As String, ByVal myFont As Font, ByVal mySize As Size) As Single
If Trim(myText).Length <= 0 Then myText = "X"
Dim currentSize As Single = CSng(myFont.Size)
Dim workFont As Font = New Font(myFont.Name, currentSize, myFont.Style, myFont.Unit)
Dim myTextSize As SizeF
If (mySize.Width >= 1) AndAlso (mySize.Height >= 1) Then
Do
currentSize += 4.0 : If currentSize > 50.0 Then Exit Do
workFont = New Font(workFont.Name, currentSize, workFont.Style, workFont.Unit)
myTextSize = TextRenderer.MeasureText(myText, workFont)
Loop Until (myTextSize.Width > mySize.Width) Or (myTextSize.Height > mySize.Height)
Do
currentSize -= 0.5 : If currentSize < 5.0 Then Exit Do
workFont = New Font(workFont.Name, currentSize, workFont.Style, workFont.Unit)
myTextSize = TextRenderer.MeasureText(myText, workFont)
Loop Until (myTextSize.Width <= mySize.Width) AndAlso (myTextSize.Height <= mySize.Height)
End If
Return currentSize
End Function