I am trying to set the font size based on the length of three strings of text
The limiting factor is the print area which is the Avery Address Label 1" X 2-5/8"
The three strings of data to be printed are represented by Global variables gv
Because the length of these three strings can vary based on the data my code to test the length is trying to compare 3 elements to make a decision on the font size. If one set is too long then it dictates the font size
The first test works if all the data is real long
The second test works but is not able to permit the third test to function. Posted CODE will make this a lot clearer. I hope
I am not sure if the failure is my test code construction as I have tried numerous designs
I have looked at this concept but feel it is not workable for my issue
StringSize = e.Graphics.MeasureString(strS, myFont)
Because I am dealing with 3 elements that are highly variable I feel my test code is not a workable concept
If a better solution can help solve this issue suggestions are desired
OR can my Test Code be fixed to work?
Test Code
Dim FL As Integer = gv_FN.Length + gv_LN.Length
If gv_AD.Length >= 24 Or FL >= 26 Or gv_CT.Length >= 16 Then
fontSIZE = 11
End If
If gv_AD.Length = 23 Or gv_AD.Length = 22 Or gv_AD.Length = 21 Or gv_AD.Length = 20 Or gv_AD.Length = 19 _
Or FL = 25 Or FL = 24 Or FL = 23 Or FL = 22 Or FL = 21 _
Or gv_CT.Length = 15 Or gv_CT.Length = 14 Or gv_CT.Length = 13 Or gv_CT.Length = 12 Then
fontSIZE = 13
End If
If gv_AD.Length <= 18 Or FL <= 20 Or gv_CT.Length <= 11 Then
fontSIZE = 15
End If
tbInfo.Text = fontSIZE.ToString
Dim labelFont As Font = New Font("Times New Roman", fontSIZE, FontStyle.Bold)
This is an EDIT with the FIX which as @Hursey suggested to use ElseIf
If gv_AD.Length >= 24 Or FL >= 26 Or gv_CT.Length >= 16 Then
fontSIZE = 11
ElseIf gv_AD.Length = 23 Or gv_AD.Length = 22 Or gv_AD.Length = 21 Or gv_AD.Length = 20 Or gv_AD.Length = 19 _
Or FL = 25 Or FL = 24 Or FL = 23 Or FL = 22 Or FL = 21 _
Or gv_CT.Length = 15 Or gv_CT.Length = 14 Or gv_CT.Length = 13 Or gv_CT.Length = 12 Then
fontSIZE = 13
Else
fontSIZE = 15
End If
tbInfo.Text = fontSIZE.ToString
Dim labelFont As Font = New Font("Times New Roman", fontSIZE, FontStyle.Bold) 'Times New Roman