By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

RichTextBox...

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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).MeasureStr ing(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"
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

Nov 21 '05 #2

P: n/a
Bob
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

"VJ" <vi********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.