views:

18

answers:

2

This question is about WinForms RichTextbox.

I have a RichTextbox with ScrollBars property set to Vertical.

I change it's RTF contents from the code and sometimes the vertical scrollbar appears disabled - when it should be enabled. This should never happen - the scrollbar should be either enabled, or not shown at all. (I had a similar issue in my VB6 app, when the scrollbar sometimes didn't appear at all when it should).

Is there any way how to force the RichTextbox scrollbars to refresh, via PInvoke or any other way to fix this issue?

Thanks.

A: 

Did you tried

this.richTextBox1.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
Anuraj
Yes, that works, of course. But I want the scrollbar to hide when it's not needed.
Jiri
A: 

I've finally figured it out! In case anyone needs this:

1) Create a new control that inherits from the richtextbox control

2) Add this code:

Public Sub FixScrollbars()
    RecreateHandle()
End Sub

3) Call it whenever you change the .RTF property.

Jiri