Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Calculate the appropriete width of string if RichTextBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marcin Waligora - 26 Oct 2004 08:33 GMT
Hi all,

I'm trying to create a read-only RichTextBox that will dynamically adjust
it's width to the string I throw into it.
It should be a perfect fit. I must use RichTextBox, because some of the text
can be in different color or be
bolded.

RichTextBox.Size doesn't work, since it is only an approximation.
Does anyone know how to calculate that??

Thanks,
Marcin Waligora
Jakob Christensen - 26 Oct 2004 13:05 GMT
Hey Marcin,

Use can use either Graphics.MeasureString or Graphics.MeasureCharacterRanges
to measure the width of a given string.  You can then set the widtch of the
RichTextBox to the found width.  You can obtain a graphics object for your
RichTextBox by calling CreateGraphics on the RichTextBox.  See the MSDN
documentation for examples of how to use MeasureString or
MeasureCharacterRanges.

HTH, Jakob.

> Hi all,
>
[quoted text clipped - 9 lines]
> Thanks,
> Marcin Waligora

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.