Ish*_*aan 5 .net c# scrollbar icsharpcode
是否可以在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;
}
}
Run Code Online (Sandbox Code Playgroud)
3)在带有文本编辑器的项目中,您可以这样调用该ShowScrollBars()方法:
editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical,false);
Run Code Online (Sandbox Code Playgroud)
此代码的技巧是根据文本行数显示垂直滚动条:
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);
}
Run Code Online (Sandbox Code Playgroud)
在文本区域控件中:
public int GetTotalNumberOfLines()
{
return this.Document.TotalNumberOfLines;
}
Run Code Online (Sandbox Code Playgroud)
ps 我正在使用此代码项目 ICSharpCode-TextEditor项目。
| 归档时间: |
|
| 查看次数: |
965 次 |
| 最近记录: |