本文整理汇总了C#中System.Windows.Forms.RichTextBox.Find方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.Find方法的具体用法?C# RichTextBox.Find怎么用?C# RichTextBox.Find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoRichTextSearch
internal static void DoRichTextSearch(RichTextBox rtbSearch, string sSearchFor, bool bHighlightAll)
{
if (rtbSearch.TextLength >= 1)
{
if (!bHighlightAll)
{
int num = Math.Min(rtbSearch.SelectionStart + 1, rtbSearch.TextLength);
rtbSearch.Find(sSearchFor, num, RichTextBoxFinds.None);
}
else
{
try
{
CommonMethods.LockWindowUpdate(rtbSearch.Handle);
rtbSearch.SelectionStart = 0;
rtbSearch.SelectionLength = rtbSearch.TextLength;
rtbSearch.SelectionBackColor = rtbSearch.BackColor;
rtbSearch.SelectionLength = 0;
if (!string.IsNullOrEmpty(sSearchFor))
{
int num1 = rtbSearch.Find(sSearchFor, 0, RichTextBoxFinds.None);
int num2 = num1;
while (num1 > -1)
{
rtbSearch.SelectionBackColor = Color.Yellow;
num1++;
if (num1 >= rtbSearch.TextLength)
{
break;
}
num1 = rtbSearch.Find(sSearchFor, num1, RichTextBoxFinds.None);
}
if (num2 > -1)
{
rtbSearch.SelectionLength = 0;
rtbSearch.SelectionStart = num2;
}
}
}
finally
{
CommonMethods.LockWindowUpdate(IntPtr.Zero);
}
}
return;
}
else
{
return;
}
}
示例2: FindTheText
private static int FindTheText(RichTextBox textBox, 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)
{
if (!textBox.Focused)
{
textBox.Focus();
}
// Obtain the location of the search string in richTextBox1.
int indexToText = textBox.Find(text, start, RichTextBoxFinds.None);
// Determine whether the text was found in richTextBox1.
if (indexToText >= 0)
{
returnValue = indexToText;
}
}
if (returnValue == -1)
{
if (start == 0)
{
MessageBox.Show("Text \"" + text + "\" was not found.", "Find text", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (MessageBox.Show("No more occurence of \"" + text + "\" was found.\nSearch from the beginning?", "Find text", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
FindTheText(textBox, text, 0);
}
}
return returnValue;
}
示例3: SpellCompare
/// <summary>
/// Compares two spells
/// </summary>
/// <param name="rtb1">RichTextBox 1 in left</param>
/// <param name="rtb2">RichTextBox 2 in right</param>
/// <param name="spell1">Compare Spell 1</param>
/// <param name="spell2">Compare Spell 2</param>
public SpellCompare(RichTextBox rtb1, RichTextBox rtb2, SpellInfoHelper spell1, SpellInfoHelper spell2)
{
new SpellInfo(rtb1, spell1);
new SpellInfo(rtb2, spell2);
var strsl = rtb1.Text.Split('\n');
var strsr = rtb2.Text.Split('\n');
var pos = 0;
foreach (var str in strsl)
{
pos += str.Length + 1;
rtb1.Select(pos - str.Length - 1, pos - 1);
if (rtb2.Find(str, RichTextBoxFinds.WholeWord) != -1)
rtb1.SelectionBackColor = str.ContainsText(_words) ? rtb1.BackColor : Color.Cyan;
else
rtb1.SelectionBackColor = Color.Salmon;
}
pos = 0;
foreach (var str in strsr)
{
pos += str.Length + 1;
rtb2.Select(pos - str.Length - 1, pos - 1);
if (rtb1.Find(str, RichTextBoxFinds.WholeWord) != -1)
rtb2.SelectionBackColor = str.ContainsText(_words) ? rtb2.BackColor : Color.Cyan;
else
rtb2.SelectionBackColor = Color.Salmon;
}
}
示例4: FindMyText
public int FindMyText(string txtToSearch, int searchStart, int searchEnd,RichTextBox rtb)
{
// Unselect the previously searched string
if (searchStart > 0 && searchEnd > 0 && indexOfSearchText >= 0)
{
rtb.Undo();
}
// Set the return value to -1 by default.
int retVal = -1;
// A valid starting index should be specified.
// if indexOfSearchText = -1, the end of search
if (searchStart >= 0 && indexOfSearchText >= 0)
{
// A valid ending index
if (searchEnd > searchStart || searchEnd == -1)
{
// Find the position of search string in RichTextBox
indexOfSearchText = rtb.Find(txtToSearch, searchStart, searchEnd, RichTextBoxFinds.None);
// Determine whether the text was found in richTextBox1.
if (indexOfSearchText != -1)
{
// Return the index to the specified search text.
retVal = indexOfSearchText;
}
}
}
return retVal;
}
示例5: SpellCompare
string[] words = new[] { "=====" }; // todo: more wodrs
#endregion Fields
#region Constructors
/// <summary>
/// Compares two spells
/// </summary>
/// <param name="rtb1">RichTextBox 1 in left</param>
/// <param name="rtb2">RichTextBox 2 in right</param>
/// <param name="spell1">Compare Spell 1</param>
/// <param name="spell2">Compare Spell 2</param>
public SpellCompare(RichTextBox rtb1, RichTextBox rtb2, SpellEntry spell1, SpellEntry spell2)
{
new SpellInfo(rtb1, spell1);
new SpellInfo(rtb2, spell2);
string[] strsl = rtb1.Text.Split('\n');
string[] strsr = rtb2.Text.Split('\n');
int pos = 0;
foreach (string str in strsl)
{
pos += str.Length + 1;
rtb1.Select(pos - str.Length - 1, pos - 1);
if (rtb2.Find(str, RichTextBoxFinds.WholeWord) != -1)
{
if (str.ContainsText(words))
{
rtb1.SelectionBackColor = rtb1.BackColor;
}
else
{
rtb1.SelectionBackColor = Color.Cyan;
}
}
else
{
rtb1.SelectionBackColor = Color.Salmon;
}
}
pos = 0;
foreach (string str in strsr)
{
pos += str.Length + 1;
rtb2.Select(pos - str.Length - 1, pos - 1);
if (rtb1.Find(str, RichTextBoxFinds.WholeWord) != -1)
{
if (str.ContainsText(words))
{
rtb2.SelectionBackColor = rtb2.BackColor;
}
else
{
rtb2.SelectionBackColor = Color.Cyan;
}
}
else
{
rtb2.SelectionBackColor = Color.Salmon;
}
}
}
示例6: Highlight
public static void Highlight(RichTextBox myRtb,string Line,Color color)
{
myRtb.SelectionBackColor = Color.White;
myRtb.Focus();
startIndex = myRtb.Find(Line, startIndex, RichTextBoxFinds.None);//Returns the start index of specific Line
if (startIndex > -1)
{
myRtb.Select(startIndex, Line.Length);//Select a line using it's Length and its StartIndex
startIndex += Line.Length;
}
else if (startIndex < 0) // Fixes the Argument Exception
{
startIndex = 0;
Highlight(myRtb, Line,color);//Call it again to highlight the Line
}
}
示例7: ConvertGreenText
public static void ConvertGreenText(string eugenStr, ref RichTextBox textBox)
{
int i = 0;
string[] parts = eugenStr.Split(GREEN_TAG, StringSplitOptions.None);
if (parts.Length > 1)
{
if (i % 2 == 0 )
{
textBox.AppendText(parts[i].Replace("#styleGreen", string.Empty));
}
else
{
AppendTextWithColor(ref textBox, parts[i], Color.Teal);
}
}
textBox.Find(GREEN_TAG[0]);
}
示例8: Replace
bool Replace(RichTextBox rTB)
{
int start = rTB.SelectionStart;
int resFind = rTB.Find(textBox1.Text, start, RichTextBoxFinds.MatchCase);
if (resFind != -1)
{
rTB.Select(resFind, textBox1.Text.Length);
rTB.SelectedText = textBox2.Text;
rTB.Select(resFind, textBox2.Text.Length);
rTB.Parent.Select();
return true;
}
else if(start != 0)
{
DialogResult result = MessageBox.Show("Продолжить с начала?", "No Results", MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.Yes)
{
int start1 = 0;
resFind = rTB.Find(textBox1.Text, start1, start, RichTextBoxFinds.MatchCase);
if (resFind != -1)
{
rTB.Select(resFind, textBox1.Text.Length);
rTB.SelectedText = textBox2.Text;
rTB.Select(resFind, textBox2.Text.Length);
rTB.Parent.Select();
return true;
}
return false;
}
else
{
return false;
}
}
return false;
}
示例9: RtbProtect
private void RtbProtect(RichTextBox rtb)
{
int i=-1;
i = rtb.Find("|", 0, RichTextBoxFinds.None);
while (i != -1)
{
rtb.Select(i, 1);
rtb.SelectionProtected = true;
if (i == rtb.TextLength - 1)
{
rtb.Select(i, 1);
rtb.SelectionProtected = true;
break;
}
else
i = rtb.Find("|", i + 1, RichTextBoxFinds.None);
}
}
示例10: format
private void format(RichTextBox rtb, string tag, Font font, Color c, int offset, string l, string r)
{
int start = 0;
int len;
while ((start = rtb.Find("<" + tag + ">", start, RichTextBoxFinds.MatchCase)) >= 0)
{
start += tag.Length + 2;
len = rtb.Find("</" + tag + ">", start, RichTextBoxFinds.MatchCase) - start;
rtb.Select(start, len);
Font stylefont = font == null ? rtb.SelectionFont : font;
if (tag == Util.BOLD)
{
rtb.SelectionFont = new Font(stylefont, FontStyle.Bold);
}
else if (tag == Util.ITALIC)
{
rtb.SelectionFont = new Font(stylefont, FontStyle.Italic);
}
else
{
rtb.SelectionFont = stylefont;
}
rtb.SelectionColor = c;
rtb.SelectionIndent += offset;
}
rtb.Rtf = rtb.Rtf.Replace("<" + tag + ">", l);
rtb.Rtf = rtb.Rtf.Replace("</" + tag + ">", r);
if (tag == Util.REF)
{
while ((start = rtb.Find("Refrain:", ++start, RichTextBoxFinds.MatchCase)) >= 0)
{
if (start == 1) //remove first \par\r
{
rtb.Rtf = rtb.Rtf.Remove(rtb.Rtf.IndexOf("Refrain:") - 6, 6);
start = 0;
}
rtb.Select(start, 8);
rtb.SelectionFont = new Font(rtb.SelectionFont, FontStyle.Bold);
rtb.SelectionColor = ResolvedRefrainForegroundColor;
rtb.SelectionIndent = 0;
}
}
}
示例11: FindStringTest
public void FindStringTest ()
{
RichTextBox rTextBox = new RichTextBox ();
rTextBox.Text = "sample text for richtextbox";
int indexToText1 = rTextBox.Find ("for");
Assert.AreEqual (12, indexToText1, "#Mtd4");
int indexToText2 = rTextBox.Find ("for", 0, 14, RichTextBoxFinds.MatchCase);
Assert.AreEqual (-1, indexToText2, "#Mtd5");
int indexToText3 = rTextBox.Find ("for", 0, 15, RichTextBoxFinds.MatchCase);
Assert.AreEqual (12, indexToText3, "#Mtd6");
int indexToText4 = rTextBox.Find ("richtextbox", 0, RichTextBoxFinds.MatchCase);
Assert.AreEqual (16, indexToText4, "#Mtd7");
int indexToText5 = rTextBox.Find ("text", RichTextBoxFinds.MatchCase);
Assert.AreEqual (7, indexToText5, "#Mtd8");
}
示例12: FindTest
public void FindTest() {
RichTextBox t = new RichTextBox();
t.Text = "Testtext and arglblah may not be what we're looking for\n, but blah Blah is";
Assert.AreEqual(t.Find(new char[] {'b', 'l', 'a', 'h'}), 9, "Find1");
Assert.AreEqual(t.Find(new char[] {'b', 'l', 'a', 'h'}, 20), 20, "Find2");
Assert.AreEqual(t.Find(new char[] {'b', 'l', 'a', 'h'}, 25, 30), -1, "Find3");
Assert.AreEqual(t.Find("blah"), 17, "Find4");
Assert.AreEqual(t.Find("blah", 10, 30, RichTextBoxFinds.None), 17, "Find5");
Assert.AreEqual(t.Find("blah", 10, 30, RichTextBoxFinds.WholeWord), -1, "Find6");
Assert.AreEqual(t.Find("blah", 10, 30, RichTextBoxFinds.MatchCase), 17, "Find7");
Assert.AreEqual(t.Find("blah", 10, 70, RichTextBoxFinds.Reverse), 62, "Find8");
Assert.AreEqual(t.Find("blah", 10, 73, RichTextBoxFinds.Reverse), 67, "Find9");
Assert.AreEqual(t.Find("blah", 10, 73, RichTextBoxFinds.Reverse | RichTextBoxFinds.MatchCase), 62, "Find10");
Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.None), 17, "Find11");
Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.WholeWord), 62, "Find12");
Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.MatchCase), 17, "Find13");
Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.Reverse), 67, "Find14");
Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.Reverse | RichTextBoxFinds.MatchCase), 62, "Find15");
Assert.AreEqual(t.Find("blah", RichTextBoxFinds.Reverse), 67, "Find16");
Assert.AreEqual(t.Find("blah", RichTextBoxFinds.MatchCase), 17, "Find17");
Assert.AreEqual(t.Find("blah", RichTextBoxFinds.WholeWord), 62, "Find18");
// Special cases
Assert.AreEqual(t.Find("blah", 10, 11, RichTextBoxFinds.None), -1, "Find19"); // Range to short to ever match
Assert.AreEqual(t.Find("blah", 17, 18, RichTextBoxFinds.None), -1, "Find20"); // Range to short to ever match, but starts matching
Assert.AreEqual(t.Find("is", RichTextBoxFinds.WholeWord), 72, "Find21"); // Last word in document
Assert.AreEqual(t.Find("for", RichTextBoxFinds.WholeWord), 52, "Find22"); // word followed by \n
Assert.AreEqual(t.Find("Testtext", RichTextBoxFinds.WholeWord), 0, "Find23"); // First word in document
Assert.AreEqual(t.Find("Testtext", RichTextBoxFinds.WholeWord | RichTextBoxFinds.Reverse), 0, "Find24"); // First word in document, searched in reverse
}
示例13: CheckRichTextBox
/// <summary>
/// Check dangerous instructions like OPEN HAND , CLOSE HAND
/// </summary>
/// <param name="rtb">RichTextBox to search in</param>
/// <param name="pos"></param>
/// <returns></returns>
private bool CheckRichTextBox(RichTextBox rtb, int pos)
{
bool res = true;
int position = pos;
foreach (KeyValuePair<string, string> s in instructionsReplace)
{
position = 0;
while ((position = rtb.Find(s.Key, position, RichTextBoxFinds.None)) > 0)
{
rtb.Select(position, s.Key.Length);
rtb.SelectionColor = Color.Red;
string text = string.Format("Instruction {0} trouvée : remplacer par {1}?", s.Key.ToString(), s.Value.ToString());
DialogResult d = MessageBox.Show(text,"Remplacer",MessageBoxButtons.YesNo);
if (d == DialogResult.Yes)
{
rtb.SelectionColor = Color.Black;
rtb.SelectedText = s.Value;
}
else
{
position += s.Key.Length + 1;
res = false;
}
}
}
return res;
}
示例14: FindCharTest
public void FindCharTest ()
{
RichTextBox rTextBox = new RichTextBox ();
rTextBox.Text = "something";
Assert.AreEqual (2, rTextBox.Find (new char [] {'m'}), "#Mtd3");
Assert.AreEqual (-1, rTextBox.Find (new char [] {'t'},5), "#Mtd3a");
Assert.AreEqual (4, rTextBox.Find (new char [] {'t'},4,5), "#Mtd3b");
}
示例15: InsertToSummary
private void InsertToSummary(string text,RichTextBox richtext)
{
BeginInvoke(new Action(() =>
{
var index = richtext.Find(text);
if (index == -1)
{
richtext.AppendText(text + Environment.NewLine);
}
}));
}