Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21248

[RESOLVED] Adjust text height to fit in label width.

$
0
0
Problem with adjusting text point size to fit in width wise to a label.

Basicly how to enumerate point sizes available in given font, so to substract correct value from previous point size?

Code below runs in endless loop, because Label1.Font.Size = Label1.Font.Size - 0.25statement does not work.

or is there more solid method?

Fontfamily (helvetica, times etc.), font point size (whole integers ie. 10, 12), field area (label width) in pixels, are defined in xml file - so only sound method to display whole text is to adjust it's point size. Currently there is slight mismatch and text is sometimes clipped. I have user scalemode defined form, which represents Left, Top, Width and Height ie. page size defined in XML file.

Labels (field) widths are defined in XML file, so label width can't be (easily) changed - as some field/texts are going to overlap.

Code:

Private Sub Form_Load()
    Me.AutoRedraw = True
    Me.Font.Name = "Arial Narrow"
    Me.Print "ABCDEFGHIJKLMNO"
    Label1.Font.Name = "Arial Narrow"
    Label1.Font.Size = 10
    Label1.Width = 109 'set to some width
End Sub

Private Sub Command1_Click()
Dim sText As String
sText = "ABCDEFGHIJKLMNO"
Label1.Caption = sText
Set Me.Font = Label1.Font
Debug.Print "Label1.Font.Size before " & Label1.Font.Size
    Do
    If Me.TextWidth(Label1.Caption) > Label1.Width Then
        Label1.Font.Size = Label1.Font.Size - 0.25
        Debug.Print Me.TextWidth(Label1.Caption)
    Else
        Exit Do
    End If
    Loop
Debug.Print "Label1.Font.Size after " & Label1.Font.Size 'Should be adjusted point size to value where text fits inside label.
End Sub


Viewing all articles
Browse latest Browse all 21248

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>