WinForms NumericUpDown を使用すると、Select(Int32, Int32) メソッドを使用して、その中のテキストの範囲を選択できます。SelectionStart、SelectionLength、および SelectedText プロパティを使用して、他のテキストボックスのようなコントロールでできるように、選択したテキストの開始点、選択した文字数、選択したテキストの部分を設定/取得する方法はありますか?
3 に答える
5
NumericUpDown コントロールには、コントロール コレクションからアクセスできる内部 TextBox があります。UpDownButtons コントロールに続く、コレクション内の 2 番目のコントロールです。WinForms はもはや開発中ではないため、NumericUpDown コントロールの基礎となるアーキテクチャは変更されないと言っても差し支えありません。
NumericUpDown コントロールから継承することで、これらの TextBox プロパティを簡単に公開できます。
public class NumBox : NumericUpDown {
private TextBox textBox;
public NumBox() {
textBox = this.Controls[1] as TextBox;
}
public int SelectionStart {
get { return textBox.SelectionStart; }
set { textBox.SelectionStart = value; }
}
public int SelectionLength {
get { return textBox.SelectionLength; }
set { textBox.SelectionLength = value; }
}
public string SelectedText {
get { return textBox.SelectedText; }
set { textBox.SelectedText = value; }
}
}
于 2013-11-08T14:33:29.110 に答える