是否可以在ICSharpCode.TextEditor中配置垂直滚动条,使默认情况下不显示垂直滚动条。只有当有人输入大量行(超出此控件的当前高度)时,才会自动出现垂直滚动条。如果可以,如何实现?
是否可以在ICSharpCode.TextEditor中配置垂直滚动条,使默认情况下不显示垂直滚动条。只有当有人输入大量行(超出此控件的当前高度)时,才会自动出现垂直滚动条。如果可以,如何实现?
很容易自己添加此功能:
1)进入命名空间ICSharpCode.TextEditor
并打开TextAreaControl
类。文件位置为:C:...\ICSharpCode.TextEditor\Project\Src\Gui\TextAreaControl.cs
2)添加一个方法来设置水平或垂直滚动条的可见性:
public void ShowScrollBars(Orientation orientation,bool isVisible)
{
if (orientation == Orientation.Vertical)
{
vScrollBar.Visible = isVisible;
}
else
{
hScrollBar.Visible = isVisible;
}
}
ShowScrollBars()
方法的方式:editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical,false);
这段代码可以根据文本行数显示垂直滚动条:
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);
}
public int GetTotalNumberOfLines()
{
return this.Document.TotalNumberOfLines;
}
PS:我正在使用这个Code Project ICSharpCode-TextEditor项目。
Orientation.Vertical
设置为Orientation.Horizontal
。 - Jeremy Thompson