1

ネットで長い間検索した後、あなたが私を助けてくれることを願っています.

私の問題: TextBox 内のテキスト全体を選択したいのですが、最後の文字の後にキャレット (カーソルの点滅) が表示されます。

常に 1 つの問題に関する情報またはキャレットを非表示にする情報を見つけました。

別々のものは問題ありませんが、組み合わせは機能しません。

// Set the focus to the TextBox
myTextBox.Focus();

// Select the complete text, but hide the caret (blinking cursor) 
myTextBox.SelectAll();

// or
// myTextBox.Select(0, myTextBox.Text.Length);

// Set the caret after the last character, but loss the selection from the text
myTextBox.CaretIndex = myTextBox.Text.Length;

そのため、最後の文字の後にキャレットが表示されますが、テキストは選択されていません

myTextBox.Focus();
myTextBox.SelectAll();
myTextBox.CaretIndex = myTextBox.Text.Length;

そのため、テキストは選択されていますが、キャレットは表示されていません。

myTextBox.Focus();
myTextBox.CaretIndex = myTextBox.Text.Length;
myTextBox.SelectAll();

それが問題です: それらの 1 つが別のものを無効にしますが、これら 2 つのことが同時に必要です

私はWPFと.Net 4.0を使用しています

助けてくれてありがとう:-)

4

2 に答える 2

-1

これは私のために働いた:

        TextBox.Text = _Text;
        System.Windows.Input.Keyboard.Focus(TextBox);

        TextBox.GotFocus += (sender, e) => {
            if (_selectAll)
            {
                //I think Caret can be set here but I didn't try it
                TextBox.SelectAll();
            }
        };
于 2014-11-17T16:24:02.190 に答える