text wrapping

say if at first the richtextbox only have its height enough for 1 line now when it reaches the end of the right it proceed to the next new line as it wrap the rtb willl wrap the text...now i wonder whether i can let the richtextbox automatically adjust the height to fit in the first and second line(just like insert text in powerpoint.) or maybe is there a way to for us to know that the text is wrap(jump to the next line)i mean is there any code which tell us that the richtextbox has wrap the text (jump to the next line)
crfAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

clifABBCommented:
After assigning the text to the RichTextBox (or in the change event), use this code:
  RichTextBox1.Height = Form1.TextHeight("X") * (Int(Form1.TextWidth(RichTextBox1.Text) / RichTextBox1.Width + 0.5) * 1.6)

The only caveat is to make the Form and the RichTextBox have the same font.
0
crfAuthor Commented:
SORRY CLIFABB I THINK U DO NOT REALLY KNOW WHAT I AM LOOKING FOR WHAT I WANT IS THAT THE RICHTEXTBOX WILL AUTOMATICALLY ADJUST ITS HEIGHT WHEN IT AUTO WRAP THE TEXT TO THE NEXT NEW LINE AND MY RICHTEXTBOX CONTAINS CHARACTER OF DIFFERENT FONTS..
0
lbkCommented:
I don't think there really is a way to do this. The only hint I can give you is to use the Line() function of the rtb control. it gives you the line number of the ##th character.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

EvanLCommented:
My idea would be to continually check the length of the text string.  When the length equals a certain amount, then increase the height of the textbox.  The certain amount mentioned above would be the number of characters it takes to fill a line.  You could have a select case statement in the text change event that would check to see if the text string length has reached certain points yet - and if so, increase the textbox height by X amount.


0
EvanLCommented:
The following code works.  You have to set the right margin of the text box correctly.  In my example, when the text length reaches 20, then increase the height of the text box.  You could have multiple If Thens or a Select Case.

Private Sub RichTextBox1_Change()
If Len(RichTextBox1.Text) = 20 Then
    RichTextBox1.Height = 750
Else
End If
End Sub
0
crfAuthor Commented:
the problem now is i will have different fontsize so when the fontsize is not the same your codes does not work anymore....
0
EvanLCommented:
Hmmm...  very true.  I assumed you would have a basic fixed-width font.  Guess it will work if you do it that way, but if you are loading something like a Word document into the rich textbox, it will hit the next line before it reaches the number of characters it would take to fill the line.  The only thing I can think of is to come up with some kind of ratio.  If the text font size is equal to a certain number, then the number of characters in one line of text before the textbox would increase in height would change.

Sounds like a difficult problem to solve if you are using multiple fonts and font sizes.

I'll keep working on it and get back to you soon..
0
EvanLCommented:
What about making the textbox width wide enough to accept any font so that the first, say, 50 characters were always on the first line, no matter what happened?

You would also run into trouble with carriage returns.

Guess you should reopen the question for others because I'm out of ideas... sorry..
0
zsiCommented:
I know how to do this but I am too tired. :)

Hey ClifABB!!!  Think "TextMetrics"!


My gift to you.  ;)
0
MAVERICKCommented:
I worked on a app where I clicked a cursor and the position in the RTF box was noted.... even though this may have aparently (absolutely!!!) nothing to do with your problem, It may be adaptable to solve your problem....

0
crfAuthor Commented:
yes maverick i think that can help me do what i can can u kindly provide me with more informations on the app u r refering to ???thank you...../
0
crfAuthor Commented:
Adjusted points to 215
0
MAVERICKCommented:
The original app was taken during a hard drive crash!
I will try to write the code suitable to your purpose as soon as time permits!
The concept is the important part!!!

0
crfAuthor Commented:
do u noe how can u detect the position of the rich text box
0
crfAuthor Commented:
Adjusted points to 230
0
KEWLCommented:
Try the 'ScaleY' method to find out how many pixels per character there is?
0
crfAuthor Commented:
kewl how do i do it????
0
vamsi_kCommented:
To be frank, I also faced this kind of problem lately.  I have created a document, in MS-Word, and saved it as RTF file format.  Next, in VB, using RichTextBox control, I have loaded this file.  Actually, while in Word, the lines were truncated automatically, when they exceeded the horizontal width of the page.  But when loaded onto the RichTextBox, the line is not truncating and going to the next line, instead, horizontal scroll bars appeared, and the line is printed as one single line.  I have to move right through the horizontal bar in-order to view the line completely.  Solution to this problem, I think will solve your problem also.

0
MAVERICKCommented:
Refer to my homepage:
http://www.geocities.com/SiliconValley/Haven/4011/
There will be a VB project 'Jon4'
Run it and it should solve your problem!

For the record, Here's the Code section
Private Sub RichTextBox1_Change()
a = RichTextBox1.GetLineFromChar(Len(RichTextBox1.Text))
'Text1.Text = a
If a < 5 Then ' Allows the box to scroll after 6 lines
RichTextBox1.Height = 400 + (a * 200)
b = RichTextBox1.SelStart
RichTextBox1.SelStart = 0 ' The following lines prevent the text from
RichTextBox1.SetFocus     ' Scrolling Top
RichTextBox1.SelStart = b
RichTextBox1.SetFocus
End If

End Sub

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.