jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
966 stars 246 forks source link

Horizontal Scrollbar is shown when it shouldn't be #10

Closed tttmack closed 9 years ago

tttmack commented 9 years ago

When the HScrollBar property is set to true, it should only display the scrollbar when it is needed but it currently displays it when it is not needed (for example when there is no text in the box or the text width is less than the width of the ScintillaNet control)

jacobslusser commented 9 years ago

What you're describing isn't a bug (or a feature that I could add) and you're not the first developer to notice that Scintilla's horizontal scrollbar works differently than say, a TextBox or RichTextBox. For performance reasons that are a bit difficult to explain, Scintilla (and ScintillaNET) takes a very lazy approach to calculating the necessity and width of the horizontal scrollbar and instead uses an assumed width.

That width is specified in the ScrollWidth property and has a default value of 2000, which will usually cause it to be displayed by default. A related property is ScrollWidthTracking which will cause the ScrollWidth property to increase when necessary, but it doesn't calculate changes which would make the horizontal scrollbar shrink or go away.

Thus, the closest you're going to get to the behavior you want is to set:

scintilla.ScrollWidth = 1;
scintilla.ScrollWidthTracking = true;

This will have the effect of hiding the horizontal scrollbar by default and expanding it as necessary. As I said though, once displayed it will never go away no matter how little text is being displayed. To do that would require constant remeasuring of the text width and a performance hit that the creators of Scintilla have chosen not to implement.

This is just one of those cases where Scintilla is different than what you expect.