次の方法で共有


RichTextBoxFinds 列挙体

RichTextBox コントロールで文字列の検索を実行する方法を指定します。

この列挙体には、メンバ値をビットごとに演算するための FlagsAttribute 属性が含まれています。

<Flags>
<Serializable>
Public Enum RichTextBoxFinds
[C#]
[Flags]
[Serializable]
public enum RichTextBoxFinds
[C++]
[Flags]
[Serializable]
__value public enum RichTextBoxFinds
[JScript]
public
   Flags
 Serializable
enum RichTextBoxFinds

解説

アプリケーションでは、 RichTextBox コントロールの Find メソッドを呼び出すことによって RichTextBox コントロール内の文字列を検索します。この列挙体を使用して、 Find メソッドが呼び出されるときの検索方法を指定できます。この列挙体から 1 つ以上の値を組み合わせて、 Find メソッドを呼び出すときの複数の検索オプションを指定できます。

メンバ

メンバ名 説明
MatchCase 大文字と小文字が正確である検索文字列のインスタンスだけを検索します。 4
NoHighlight 検索文字列は、見つかっても強調表示されません。 8
None 検索で見つかるインスタンスが検索文字列の語句に完全一致であるかどうかにかかわらず、検索文字列に一致するインスタンスをすべて検索します。 0
Reverse 検索はコントロールのドキュメントの末尾から開始され、先頭に向かって実行されます。 16
WholeWord 検索文字列の語句に完全一致するインスタンスだけを検索します。 2

使用例

[Visual Basic, C#, C++] RichTextBox の内容全体で文字列を検索し、最初に見つかった文字列をメソッドのテキスト パラメータに渡す例を次に示します。検索開始位置は、メソッドの start パラメータで指定します。 RichTextBox 内で検索文字列が見つかると、見つかったテキストの最初の文字のインデックス位置が返され、見つかったテキストが強調表示されます。それ以外の場合は -1 の値が返されます。この例では、指定した検索文字列の大文字と小文字を一致させる検索オプションも指定されています。この例は、このメソッドが richTextBox1 という名前の RichTextBox を保持する Form のクラス内にあることを前提にしています。この例を使用して、検索テキストの最初のインスタンスが見つかったら、"Find Next" 入力操作を実行して、そのテキストのほかのインスタンスを検索できます。

 
Public Function FindMyText(text As String, start As Integer) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = - 1
    
    ' Ensure that a search string has been specified and a valid start point.
    If text.Length > 0 And start >= 0 Then
        ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(text, start, _
            RichTextBoxFinds.MatchCase)
        ' Determine whether the text was found in richTextBox1.
        If indexToText >= 0 Then
            returnValue = indexToText
        End If
    End If
    
    Return returnValue
End Function


[C#] 
public int FindMyText(string text, int start)
{
   // Initialize the return value to false by default.
   int returnValue = -1;

   // Ensure that a search string has been specified and a valid start point.
   if (text.Length > 0 && start >= 0) 
   {
      // Obtain the location of the search string in richTextBox1.
      int indexToText = richTextBox1.Find(text, start, RichTextBoxFinds.MatchCase);
      // Determine whether the text was found in richTextBox1.
      if(indexToText >= 0)
      {
         returnValue = indexToText;
      }
   }

   return returnValue;
}


[C++] 
public:
int FindMyText(String* text, int start)
{
   // Initialize the return value to false by default.
   int returnValue = -1;

   // Ensure that a search string has been specified and a valid start point.
   if (text->Length > 0 && start >= 0) 
   {
      // Obtain the location of the search string in richTextBox1.
      int indexToText = richTextBox1->Find(text, start, RichTextBoxFinds::MatchCase);
      // Determine whether the text was found in richTextBox1.
      if(indexToText >= 0)
      {
         returnValue = indexToText;
      }
   }

   return returnValue;
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

System.Windows.Forms 名前空間 | RichTextBox | RichTextBox.Find