Is it possible to configure vertical scrolling in ICSharpCode.TextEditor such that by default no vertical scrollbar is visible. And that only when someone types a lot of lines (beyond current height of this control) that a vertical scrollbar appears automatically. If yes, how?
Asked
Active
Viewed 1,293 times
1 Answers
1
Its easy to add the function yourself:
1) Goto the namespace ICSharpCode.TextEditor
and open the TextAreaControl
class. The file location is: C:...\ICSharpCode.TextEditor\Project\Src\Gui\TextAreaControl.cs
2) Add a method to set the visibility of the Horizontal or Vertical scrollbar:
public void ShowScrollBars(Orientation orientation,bool isVisible)
{
if (orientation == Orientation.Vertical)
{
vScrollBar.Visible = isVisible;
}
else
{
hScrollBar.Visible = isVisible;
}
}
3) In the project with the TextEditor, this is how you call the ShowScrollBars()
method:
editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical,false);
This code does the trick to show the vertical scrollbar based on the number of text lines:
public TextEditorForm()
{
InitializeComponent();
AddNewTextEditor("New file");
SetSyntaxHighlighting("Mathematica");
editor.ActiveTextAreaControl.TextEditorProperties.IndentationSize = 0;
editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical,false);
editor.TextChanged += new EventHandler(editor_TextChanged);
}
void editor_TextChanged(object sender, EventArgs e)
{
bool isVisible = (editor.ActiveTextAreaControl.GetTotalNumberOfLines > editor.ActiveTextAreaControl.TextArea.TextView.VisibleLineCount);
editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical, isVisible);
}
In the TextAreaControl:
public int GetTotalNumberOfLines()
{
return this.Document.TotalNumberOfLines;
}
ps I'm using this Code Project ICSharpCode-TextEditor project.

Jeremy Thompson
- 61,933
- 36
- 195
- 321
-
Is it also possible to hide the Horizontal ScrollBar ? I checked the code and api-calls, but I cannot find it. – Stef Heyenrath Aug 07 '14 at 21:00
-
I haven't got the code open in front of me, though you should be able to set the `Orientation.Vertical` to `Orientation.Horizontal` – Jeremy Thompson Aug 08 '14 at 02:28
-
thanks, yes I know but I asked the wrong question, I wanted to know if there is a way to determine the total number of columns / max characters on a line to see if it's possible to automatically hide the HScrollBar based on that logic. – Stef Heyenrath Aug 08 '14 at 07:02