Hello,
I am trying to create a textbox that resizes as the user type data in it to fit the text. I am currently using the textwidth and textheight methods but they seems working weirdly. Those methods return me an appropriate value but it's too small to fit the text in it.
Here is my code
Thanks
Private Sub Text1_Change()
Dim sinFontSize As Single
Dim strFontName As String
Dim str As String
Dim intLen As Integer
Dim intHei As Integer
str = Me.Text1
' stock the original form values
sinFontSize = Me.FontSize
strFontName = Me.FontName
' set the form values to those of the textbox
Me.FontSize = Me.Text1.FontSize
Me.FontName = Me.Text1.FontName
' calculate the lenght and height of the textbox
intLen = Picture1.TextWidth(str)
intHei = Picture1.TextHeight(str)
' resize the textbox
Me.Text1.Width = intLen
Me.Text1.Height = intHei
' set the form to it's original values
Me.FontSize = sinFontSize
Me.FontName = strFontName
End Sub
I am trying to create a textbox that resizes as the user type data in it to fit the text. I am currently using the textwidth and textheight methods but they seems working weirdly. Those methods return me an appropriate value but it's too small to fit the text in it.
Here is my code
Thanks
Private Sub Text1_Change()
Dim sinFontSize As Single
Dim strFontName As String
Dim str As String
Dim intLen As Integer
Dim intHei As Integer
str = Me.Text1
' stock the original form values
sinFontSize = Me.FontSize
strFontName = Me.FontName
' set the form values to those of the textbox
Me.FontSize = Me.Text1.FontSize
Me.FontName = Me.Text1.FontName
' calculate the lenght and height of the textbox
intLen = Picture1.TextWidth(str)
intHei = Picture1.TextHeight(str)
' resize the textbox
Me.Text1.Width = intLen
Me.Text1.Height = intHei
' set the form to it's original values
Me.FontSize = sinFontSize
Me.FontName = strFontName
End Sub