代码之家  ›  专栏  ›  技术社区  ›  Ishaan

icsharpcode.textEditor垂直滚动

  •  5
  • Ishaan  · 技术社区  · 15 年前

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jeremy Thompson    12 年前

    自己添加功能很容易:

    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)在使用文本编辑器的项目中,这是您调用 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我用这个 Code Project ICSharpCode-TextEditor 项目。

    推荐文章