デフォルトで垂直スクロールバーが表示されないように、ICSharpCode.TextEditorで垂直スクロールを構成することは可能ですか。そして、誰かが(このコントロールの現在の高さを超えて)多くの行を入力した場合にのみ、垂直スクロールバーが自動的に表示されます。はいの場合、どのように?
1211 次
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);
}
TextAreaControl で:
public int GetTotalNumberOfLines()
{
return this.Document.TotalNumberOfLines;
}
ps私はこのコードプロジェクトICSharpCode-TextEditorプロジェクトを使用しています。
于 2013-04-28T03:23:47.027 に答える