ICSharp code.TextEditor Veritical滚动code、ICSharp、Veritical、TextEditor

2023-09-05 00:28:13 作者:执笔梦一场

是否可以设置垂直滚动的ICSharp code.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)转到命名空间 ICSharp code.TextEditor ,然后打开 TextAreaControl 类。该文件的位置为:C:\ ICSharp code.TextEditor \项目的\ src \桂\ 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)与文本编辑的项目,这是你如何调用 ShowScrollBars()方法:

editor.ActiveTextAreaControl.ShowScrollBars(Orientation.Vertical,false);

这code的伎俩,以显示基于文本行数垂直滚动条:

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

附言:我用这个 code ++项目ICSharp code-文本编辑的项目。

 
精彩推荐
图片推荐