5

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?

4

1 回答 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;
    }
}

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

在文本区域控件中:

public int GetTotalNumberOfLines()
{
    return this.Document.TotalNumberOfLines;
}

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

于 2013-04-28T03:23:47.027 回答