RichTextBoxの検索フォームを作成するにはどうすればよいですか?
質問
可能であれば、大文字と小文字を区別して検索し、大文字と小文字を区別します。私を始めるためのリンクさえいただければ幸いです。
解決
アップ検索についてはわかりませんが、見つける限りこのようなものを使用できます
int selStart = ControltoSearch.SelectionStart;
int selLength = ControltoSearch.SelectionLength;
int newLength = SearchFor.Length;
int newStart = searchIn.IndexOf(SearchFor, selStart + selLength, compareType);
ControltoSearch.SelectionStart = newStart >= 0 ? newStart : 0;
ControltoSearch.SelectionLength = newLength;
ControltoSearch.ScrollToCaret();
ControltoSearch.Focus();
return newStart;
一致したケースでは、テキストの検索とテキストの検索の両方で String.ToLowerInvariant()
を使用できます。それ以外の場合、 String.Contains()
は大文字と小文字を区別します
searchIn.ToLowerInvariant().Contains(SearchFor.ToLowerInvariant())
他のヒント
「検索」を使用できます。リッチテキストボックス自体のメソッド。
「Match Case」のチェックボックスを使用してフォームを設定した場合、および[検索]のチェックボックス; RichTextBoxコントロールを取り込むControlToSearchという名前の検索フォームにプロパティを追加しました。次のようなことができます。
RichTextBoxFinds options = RichTextBoxFinds.None;
int from = ControlToSearch.SelectionStart;
int to = ControlToSearch.TextLength - 1;
if (chkMatchCase.Checked)
{
options = options | RichTextBoxFinds.MatchCase;
}
if (chkSearchUp.Checked)
{
options = options | RichTextBoxFinds.Reverse;
to = from;
from = 0;
}
int start = 0;
start = ControlToSearch.Find(txtSearchText.Text, from, to, options);
if (start > 0)
{
ControlToSearch.SelectionStart = start;
ControlToSearch.SelectionLength = txtSearchText.TextLength;
ControlToSearch.ScrollToCaret();
ControlToSearch.Refresh();
ControlToSearch.Focus();
}
else
{
MessageBox.Show("No match found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
所属していません StackOverflow