问题描述
是否可以在ICSharpCode.TextEditor中配置垂直滚动,以便默认情况下看不到垂直滚动条.而且只有当有人键入很多行(超出此控件的当前高度)时,垂直滚动条才会自动出现.如果是,怎么办?
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?
推荐答案
您可以轻松添加函数:
1)转到名称空间ICSharpCode.TextEditor
并打开TextAreaControl
类.文件位置为:C:... \ ICSharpCode.TextEditor \ Project \ Src \ Gui \ TextAreaControl.cs
1) Goto the namespace ICSharpCode.TextEditor
and open the TextAreaControl
class. The file location is: C:...\ICSharpCode.TextEditor\Project\Src\Gui\TextAreaControl.cs
2)添加一种方法来设置水平"或垂直"滚动条的可见性:
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)在带有TextEditor的项目中,这就是调用ShowScrollBars()
方法的方式:
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);
}
在TextAreaControl中:
In the TextAreaControl:
public int GetTotalNumberOfLines()
{
return this.Document.TotalNumberOfLines;
}
ps我正在使用此代码项目ICSharpCode-TextEditor 项目
ps I'm using this Code Project ICSharpCode-TextEditor project.
这篇关于ICSharpCode.TextEditor垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!