RichTextBox 内で選択されているテキストを取得または設定します。
Overrides Public Property SelectedText As String
[C#]
public override string SelectedText {get; set;}
[C++]
public: __property String* get_SelectedText();public: __property void set_SelectedText(String*);
[JScript]
public override function get SelectedText() : String;public override function set SelectedText(String);
プロパティ値
コントロールで選択されているテキストを表す文字列。
使用例
[Visual Basic, C#, C++] SelectionFont 、 SelectedText 、 SelectionColor の各プロパティと共に SelectionBullet プロパティを使用して、 RichTextBox コントロール内に箇条書きリストを作成する方法を次の例に示します。この例は、 richTextBox1
という名前の RichTextBox コントロールがフォーム上で作成されていることを前提にしています。
Private Sub WriteTextToRichTextBox()
' Clear all text from the RichTextBox;
richTextBox1.Clear()
' Set the font for the opening text to a larger Arial font;
richTextBox1.SelectionFont = New Font("Arial", 16)
' Assign the introduction text to the RichTextBox control.
RichTextBox1.SelectedText = "The following is a list of bulleted items:" + ControlChars.Cr
' Set the Font for the first item to a smaller size Arial font.
richTextBox1.SelectionFont = New Font("Arial", 12)
' Specify that the following items are to be added to a bulleted list.
richTextBox1.SelectionBullet = True
' Set the color of the item text.
richTextBox1.SelectionColor = Color.Red
' Assign the text to the bulleted item.
richTextBox1.SelectedText = "Apples" + ControlChars.Cr
' Apply same font since font settings do not carry to next line.
richTextBox1.SelectionFont = New Font("Arial", 12)
richTextBox1.SelectionColor = Color.Orange
richTextBox1.SelectedText = "Oranges" + ControlChars.Cr
richTextBox1.SelectionFont = New Font("Arial", 12)
richTextBox1.SelectionColor = Color.Purple
richTextBox1.SelectedText = "Grapes" + ControlChars.Cr
' End the bulleted list.
richTextBox1.SelectionBullet = False
' Specify the font size and string for text displayed below bulleted list.
richTextBox1.SelectionFont = New Font("Arial", 16)
richTextBox1.SelectedText = "Bulleted Text Complete!"
End Sub
[C#]
private void WriteTextToRichTextBox()
{
// Clear all text from the RichTextBox;
richTextBox1.Clear();
// Set the font for the opening text to a larger Arial font;
richTextBox1.SelectionFont = new Font("Arial", 16);
// Assign the introduction text to the RichTextBox control.
richTextBox1.SelectedText = "The following is a list of bulleted items:" + "\n";
// Set the Font for the first item to a smaller size Arial font.
richTextBox1.SelectionFont = new Font("Arial", 12);
// Specify that the following items are to be added to a bulleted list.
richTextBox1.SelectionBullet = true;
// Set the color of the item text.
richTextBox1.SelectionColor = Color.Red;
// Assign the text to the bulleted item.
richTextBox1.SelectedText = "Apples" + "\n";
// Apply same font since font settings do not carry to next line.
richTextBox1.SelectionFont = new Font("Arial", 12);
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "Oranges" + "\n";
richTextBox1.SelectionFont = new Font("Arial", 12);
richTextBox1.SelectionColor = Color.Purple;
richTextBox1.SelectedText = "Grapes" + "\n";
// End the bulleted list.
richTextBox1.SelectionBullet = false;
// Specify the font size and string for text displayed below bulleted list.
richTextBox1.SelectionFont = new Font("Arial", 16);
richTextBox1.SelectedText = "Bulleted Text Complete!";
}
[C++]
private:
void WriteTextToRichTextBox() {
// Clear all text from the RichTextBox;
richTextBox1->Clear();
// Set the font for the opening text to a larger Arial font;
richTextBox1->SelectionFont = new System::Drawing::Font(S"Arial", 16);
// Assign the introduction text to the RichTextBox control.
richTextBox1->SelectedText = S"The following is a list of bulleted items: \n";
// Set the Font for the first item to a smaller size Arial font.
richTextBox1->SelectionFont = new System::Drawing::Font(S"Arial", 12);
// Specify that the following items are to be added to a bulleted list.
richTextBox1->SelectionBullet = true;
// Set the color of the item text.
richTextBox1->SelectionColor = Color::Red;
// Assign the text to the bulleted item.
richTextBox1->SelectedText = S"Apples \n";
// Apply same font since font settings do not carry to next line.
richTextBox1->SelectionFont = new System::Drawing::Font(S"Arial", 12);
richTextBox1->SelectionColor = Color::Orange;
richTextBox1->SelectedText = S"Oranges \n";
richTextBox1->SelectionFont = new System::Drawing::Font(S"Arial", 12);
richTextBox1->SelectionColor = Color::Purple;
richTextBox1->SelectedText = S"Grapes \n";
// End the bulleted list.
richTextBox1->SelectionBullet = false;
// Specify the font size and string for text displayed below bulleted list.
richTextBox1->SelectionFont = new System::Drawing::Font(S"Arial", 16);
richTextBox1->SelectedText = S"Bulleted Text Complete!";
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
RichTextBox クラス | RichTextBox メンバ | System.Windows.Forms 名前空間