RichTextBox...

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

How can you automatically increase size of (Height and Width) of a TextBox
when the user types in the box (as in powerpoint for example). .

VJ
 
VJ,

Just something made quick and dirty, althoug tested. I did not understand if
you did mean a richtextbox as in the subject or a textbox as in your
message.

This goes only about the width however it shows as a sample nice.

Maybe you can use it as a start?

Cor
\\\\
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Width = 60
End Sub
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If TextBox1.Text <> "" Then
Dim CharWidth As Integer = _
CInt(Graphics.FromHwnd(TextBox1.Handle).MeasureString(TextBox1.Text,
_
TextBox1.Font).Width / CLng(TextBox1.Text.Length))
If TextBox1.Text.Length * CharWidth > 60 Then
TextBox1.Width = CharWidth * TextBox1.Text.Length
Else
Me.TextBox1.Width = 60
End If
End If
End Sub

"VJ"
 
Word of warning: unless you're using Whidbey, MeasureString is not accurate
to either TextBox or RichTextBox because GDI+ renders text completely
differently. You can work out an adjustment multiplier to fix this somewhat,
but it will never be perfect.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top