是否可以在ICSharpCode.TextEditor中配置垂直滚动,以便在默认情况下不显示垂直滚动条。而且,只有当某人键入许多行(超出此控件的当前高度)时,垂直滚动条才会自动出现。如果是,怎么做?
发布于 2013-04-28 03:23:47
很容易自己添加函数:
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;
}
}3)在使用TextEditor的项目中,您可以这样调用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);
}在TextAreaControl中:
public int GetTotalNumberOfLines()
{
return this.Document.TotalNumberOfLines;
}ps我正在使用这个代码项目ICSharpCode-TextEditor项目。
https://stackoverflow.com/questions/3476014
复制相似问题