From: Tor Inge Rislaa on
Finding the width of a text

I need to find the width of a text. When the user change the font in a
textbox I want the textbox to fit the text automatically by changing
txtMyTextBox.Width according to the actual width of the text. It can also be
useful to know the actual height when using multiline textbox. Is this
possible?

TIRislaa


From: "Eric Dreksler" <ericd AT accessoneinc DOT on
me.CreateGraphics.MeasureString(txtMyTextBox.Text,me.Font)

Eric Dreksler

"Tor Inge Rislaa" <nospam.tor.inge(a)rislaa.no> wrote in message
news:Ua7Rd.9398$IW4.224134(a)news2.e.nsc.no...
> Finding the width of a text
>
> I need to find the width of a text. When the user change the font in a
> textbox I want the textbox to fit the text automatically by changing
> txtMyTextBox.Width according to the actual width of the text. It can also
> be
> useful to know the actual height when using multiline textbox. Is this
> possible?
>
> TIRislaa
>
>


From: Tor Inge Rislaa on
Thank you, works OK!

TIRislaa

"Eric Dreksler" <ericd AT accessoneinc DOT com> skrev i melding
news:uGtpMETFFHA.3376(a)TK2MSFTNGP12.phx.gbl...
> me.CreateGraphics.MeasureString(txtMyTextBox.Text,me.Font)
>
> Eric Dreksler
>
> "Tor Inge Rislaa" <nospam.tor.inge(a)rislaa.no> wrote in message
> news:Ua7Rd.9398$IW4.224134(a)news2.e.nsc.no...
> > Finding the width of a text
> >
> > I need to find the width of a text. When the user change the font in a
> > textbox I want the textbox to fit the text automatically by changing
> > txtMyTextBox.Width according to the actual width of the text. It can
also
> > be
> > useful to know the actual height when using multiline textbox. Is this
> > possible?
> >
> > TIRislaa
> >
> >
>
>


From: Jay B. Harlow [MVP - Outlook] on
Eric & TIRislaa,
Remember to be very certain to Dispose of the Graphics object that
CreateGraphics return, other wise you can have a serious resource leak &
your program could stop working...

Dim gr As Graphics = Me.CreateGraphics()
Dim sz As Size
Try
sz = gr.MeasureString(txtMyTextBox.Text,me.Font)
Finally
gr.Dispose()
End Try

VS.NET 2005 (aka Whidbey due out later in 2005)
http://lab.msdn.microsoft.com/vs2005/ will include a Using statement to
simplify the above:

Dim sz As Size
Using gr As Graphics = Me.CreateGraphics()
sz = gr.MeasureString(txtMyTextBox.Text,me.Font)
End Using

Hope this helps
Jay

"Eric Dreksler" <ericd AT accessoneinc DOT com> wrote in message
news:uGtpMETFFHA.3376(a)TK2MSFTNGP12.phx.gbl...
> me.CreateGraphics.MeasureString(txtMyTextBox.Text,me.Font)
>
> Eric Dreksler
>
> "Tor Inge Rislaa" <nospam.tor.inge(a)rislaa.no> wrote in message
> news:Ua7Rd.9398$IW4.224134(a)news2.e.nsc.no...
>> Finding the width of a text
>>
>> I need to find the width of a text. When the user change the font in a
>> textbox I want the textbox to fit the text automatically by changing
>> txtMyTextBox.Width according to the actual width of the text. It can also
>> be
>> useful to know the actual height when using multiline textbox. Is this
>> possible?
>>
>> TIRislaa
>>
>>
>
>


From: Dennis on
Do you then have to still dispose gr or has M'soft figured out yet how to
dispose of objects with user intervention?

"Jay B. Harlow [MVP - Outlook]" wrote:

> Eric & TIRislaa,
> Remember to be very certain to Dispose of the Graphics object that
> CreateGraphics return, other wise you can have a serious resource leak &
> your program could stop working...
>
> Dim gr As Graphics = Me.CreateGraphics()
> Dim sz As Size
> Try
> sz = gr.MeasureString(txtMyTextBox.Text,me.Font)
> Finally
> gr.Dispose()
> End Try
>
> VS.NET 2005 (aka Whidbey due out later in 2005)
> http://lab.msdn.microsoft.com/vs2005/ will include a Using statement to
> simplify the above:
>
> Dim sz As Size
> Using gr As Graphics = Me.CreateGraphics()
> sz = gr.MeasureString(txtMyTextBox.Text,me.Font)
> End Using
>
> Hope this helps
> Jay
>
> "Eric Dreksler" <ericd AT accessoneinc DOT com> wrote in message
> news:uGtpMETFFHA.3376(a)TK2MSFTNGP12.phx.gbl...
> > me.CreateGraphics.MeasureString(txtMyTextBox.Text,me.Font)
> >
> > Eric Dreksler
> >
> > "Tor Inge Rislaa" <nospam.tor.inge(a)rislaa.no> wrote in message
> > news:Ua7Rd.9398$IW4.224134(a)news2.e.nsc.no...
> >> Finding the width of a text
> >>
> >> I need to find the width of a text. When the user change the font in a
> >> textbox I want the textbox to fit the text automatically by changing
> >> txtMyTextBox.Width according to the actual width of the text. It can also
> >> be
> >> useful to know the actual height when using multiline textbox. Is this
> >> possible?
> >>
> >> TIRislaa
> >>
> >>
> >
> >
>
>
>