如何自动改变textbox中字体的大小,来适用textbox的长度

解决方案 »

  1.   

    Private Sub Text1_Change()
        Dim i As Long
        For i = 100 To 1 Step -1
            Me.FontSize = i
            If Me.TextWidth(Text1.Text) <= Text1.Width Then
                Text1.FontSize = i
                Exit For
            End If
        Next
    End Sub
    笨方法,很慢,哈哈
      

  2.   

    也来个笨办法
    Private Sub Text2_Change()
        Cls
        l = Len(Text2)
        If l > 0 Then
        fnt = 100 / l
        End If
        Text2.FontSize = fnt
    End Sub
      

  3.   

    感觉应该是如何自动改变textbox的长度,来适用textbox中字的多少。
      

  4.   

    为什么不反过来考虑呢? ---改变textbox宽度,这样可能效率更高
      

  5.   

    LZ:设置Text1的属性MultiLine为True,下列代码的效果稍许不笨些,哈哈!
    Private Sub Text1_Change()
        Static i As Single
        Static l As Integer
        l = Len(Text1)
        l = l + 15
        i = 40 / Sqr(l)
        Text1.FontSize = i
    End Sub
      

  6.   

    感觉去改变textbox的宽度还更实际一些。