2010-08-13 196 views
5

是否可以在ICSharpCode.TextEditor中配置垂直滾動,使默認情況下不顯示垂直滾動條。只有當有人輸入很多行(超出此控件的當前高度)時,纔會自動顯示垂直滾動條。如果是,如何?ICSharpCode.TextEditor垂直滾動

+0

+1不再是風滾草:) – 2013-04-28 03:24:17

回答

1

它很容易添加自己的功能:

1)轉到命名空間ICSharpCode.TextEditor並打開TextAreaControl類。該文件的位置是:C:\ ICSharpCode.TextEditor \項目的\ src \桂\ TextAreaControl.cs

2)添加一個方法來設置水平或垂直滾動​​條的可見性:

​​

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

在TextAreaControl:我使用這個Code Project ICSharpCode-TextEditor項目

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

PS。

+0

也可以隱藏水平滾動條?我檢查了代碼和API調用,但我找不到它。 – 2014-08-07 21:00:56

+0

我還沒有在我面前打開代碼,但你應該能夠設置'Orientation.Vertical'到'Orientation.Horizo​​ntal' – 2014-08-08 02:28:21

+0

謝謝,是的,我知道但我問了錯誤的問題,我想知道如果有一種方法可以確定一行上的列/最大字符總數,以查看是否可以基於該邏輯自動隱藏HScrollBar。 – 2014-08-08 07:02:30