RichTextBox.SelectionLength プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As RichTextBox Dim value As Integer value = instance.SelectionLength instance.SelectionLength = value
public: virtual property int SelectionLength { int get () override; void set (int value) override; }
/** @property */ public int get_SelectionLength () /** @property */ public void set_SelectionLength (int value)
public override function get SelectionLength () : int public override function set SelectionLength (value : int)
テキスト ボックス内で選択されている文字の数。

このプロパティを使用すると、選択されたテキストに対して操作を実行する前に、テキスト ボックス コントロールで文字が選択されているかどうかを判断できます。また、このプロパティを使用して、for ループ内の単一文字タスクを実行するときに、選択されている文字の合計数 (空白も含む) も判断できます。

SelectionLength プロパティを使用して、RichTextBox 内でテキストが選択されているかどうかを確認する方法を次のコード例に示します。この例では、richTextBox1 という名前の RichTextBox コントロールがフォームに追加されている必要があります。また、コントロールで選択されているテキストが richTextBox1 に含まれている必要もあります。
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
private void ModifySelectedText() { // Determine if text is selected in the control. if (richTextBox1.SelectionLength > 0) { // Set the color of the selected text in the control. richTextBox1.SelectionColor = Color.Red; // Set the font of the selected text to bold and underlined. richTextBox1.SelectionFont = new Font("Arial",10,FontStyle.Bold | FontStyle.Underline); // Protect the selected text from modification. richTextBox1.SelectionProtected = true; } }
private: void ModifySelectedText() { // Determine if text is selected in the control. if ( richTextBox1->SelectionLength > 0 ) { // Set the color of the selected text in the control. richTextBox1->SelectionColor = Color::Red; // Set the font of the selected text to bold and underlined. richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",10,static_cast<FontStyle>(FontStyle::Bold | FontStyle::Underline) ); // Protect the selected text from modification. richTextBox1->SelectionProtected = true; } }
private void ModifySelectedText() { // Determine if text is selected in the control. if (richTextBox1.get_SelectionLength() > 0) { // Set the color of the selected text in the control. richTextBox1.set_SelectionColor(Color.get_Red()); // Set the font of the selected text to bold and underlined. richTextBox1.set_SelectionFont(new Font("Arial", 10, FontStyle. Bold | FontStyle.Underline)); // Protect the selected text from modification. richTextBox1.set_SelectionProtected(true); } } //ModifySelectedText

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からRichTextBox.SelectionLength プロパティを検索する場合は、下記のリンクをクリックしてください。

- RichTextBox.SelectionLength プロパティのページへのリンク