|
-
Oct 18th, 2009, 03:18 PM
#1
Thread Starter
Member
[RESOLVED] Size Rich Text Box using size of text
Hi All,
I have a rich text box that have a paragraph in it (the parragraph may change). The user is able to decide what type and/or size of font he whishes to view the text in. My problem is that not more that an average of four words per line should be displayed per line. My idea was to size the rtb so that it automatically wrap the text to and average of 4 words per line. This I would do by determining the average width of a word (number of characters) in the paragraph, multiplying it by the width in pixels or twips of a character and then multiplying by 4 to get the average required length of a line. It does not need to be exact as long as I can get as close as possible to 4 words per line.
Sample text:
My Father walks to the market every day to buy fresh bread and milk for the house.
Result expected:
My Father walks
to the market every
day to buy fresh
bread and milk for
the house.
Notice some lines may be slightly longer as long as the average is 4 words per line.
My problem is that I dont know how to determine the width of a character in order to ultimately determine the width of a sentence.
I would appreciate some help.
If there is a better way of solving the problem, I am open to suggestions.
Regards
-
Oct 18th, 2009, 03:32 PM
#2
Re: Size Rich Text Box using size of text
try this:
vb Code:
Dim gr As Graphics = Graphics.FromHwnd(RichTextBox1.Handle)
Dim wordSize As SizeF
wordSize = gr.MeasureString("word", RichTextBox1.Font, RichTextBox1.Size, Drawing.StringFormat.GenericTypographic)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 18th, 2009, 04:06 PM
#3
Thread Starter
Member
Re: Size Rich Text Box using size of text
Thanx Paul,
It did the trick.
Your help was much appreciated.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|