Hi,
I am developing an windows application in vb.net.
in this project i want to set the Richtextbox height according to the content in that richtextbox. For this i want to call the Richtextbox textchanged event on button click

Here is my code but i got error

on button click

 RichAll_KeyPress(sender, New KeyPressEventArgs(e))

and

 Private Sub RichAll_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
        Dim tempFont As Font = DirectCast(sender, RichTextBox).Font

        Dim textLength As Integer = DirectCast(sender, RichTextBox).Text.Length

        Dim textLines As Integer = DirectCast(sender,    RichTextBox).GetLineFromCharIndex         (textLength) + 1

        Dim Margin As Integer = DirectCast(sender, RichTextBox).Bounds.Height - DirectCast(sender, RichTextBox).ClientSize.Height

        DirectCast(sender, RichTextBox).Height = (TextRenderer.MeasureText(" ", tempFont).Height * textLines) + Margin + 2

 End Sub

How i can solve the issue
can i call textchanged event

Thanks in advance...

@bhagvatshindhe

;-( What do you want from me? Do you really want to be ban? Please read the rules before posting again, in particular the 'keep it clear'. If you hit 10 infraction points your account gets an automatic ban, so it is worth obeying the rules if you want to continue to benefit from DaniWeb help.

Please use BB code tags while posting source program.

[code]

.... [/code]

hi..

following code works for me.. see if u can use it:

Me.RichTextBox1.Height = TextRenderer.MeasureText(" ", Me.RichTextBox1.Font).Height * Me.RichTextBox1.Lines.Length

Thanks a lot sandeepparekh9 its working For me.....

Thanks once again....

Hi suppose richtextbox contain the image then its not working

are u loading a richtext file (.doc,.rtf,.docx) into the richtextbox control?

HI,
No i am adding the data from the database (or and richtextbox copy and paste into another richtextbox)

Hi ,
problem solved by finding the size of the object(image) and add it to the height.
Thanks for reply ..sandeepparekh9

Hi,
solve the problem by finding the height of the object(image) and add it to the height of the Richtextbox.