ICSharpCode.TextEditor 垂直滚动

5

是否可以在ICSharpCode.TextEditor中配置垂直滚动条,使默认情况下不显示垂直滚动条。只有当有人输入大量行(超出此控件的当前高度)时,才会自动出现垂直滚动条。如果可以,如何实现?

1个回答

1

很容易自己添加此功能:

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;
    }
}

在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:我正在使用这个Code Project ICSharpCode-TextEditor项目。


是否也可以隐藏水平滚动条?我已经检查了代码和API调用,但是找不到它。 - Stef Heyenrath
我手头没有代码,但你应该能够将 Orientation.Vertical 设置为 Orientation.Horizontal - Jeremy Thompson
谢谢,是的我知道但我问错了问题,我想知道是否有一种方法来确定一行中的总列数/最大字符数,以便根据该逻辑自动隐藏HScrollBar。 - Stef Heyenrath

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接