首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ICSharpCode.TextEditor垂直滚动

ICSharpCode.TextEditor垂直滚动
EN

Stack Overflow用户
提问于 2010-08-13 10:30:43
回答 1查看 1.3K关注 0票数 5

是否可以在ICSharpCode.TextEditor中配置垂直滚动,以便在默认情况下不显示垂直滚动条。而且,只有当某人键入许多行(超出此控件的当前高度)时,垂直滚动条才会自动出现。如果是,怎么做?

EN

回答 1

Stack Overflow用户

发布于 2013-04-28 03:23:47

很容易自己添加函数:

1)转到名称空间ICSharpCode.TextEditor并打开TextAreaControl类。文件位置是: C:...\ICSharpCode.TextEditor\Project\Src\Gui\TextAreaControl.cs

2)添加一个方法来设置水平或垂直滚动条的可见性:

代码语言:javascript
复制
public void ShowScrollBars(Orientation orientation,bool isVisible)
{
    if (orientation == Orientation.Vertical)
    {
        vScrollBar.Visible = isVisible;
    }
    else
    {
        hScrollBar.Visible = isVisible;
    }
}

3)在使用TextEditor的项目中,您可以这样调用ShowScrollBars()方法:

代码语言:javascript
复制
editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical,false);

这段代码可以根据文本行数显示垂直滚动条:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
public int GetTotalNumberOfLines()
{
    return this.Document.TotalNumberOfLines;
}

ps我正在使用这个代码项目ICSharpCode-TextEditor项目。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3476014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档