本文整理匯總了C#中System.Windows.Forms.RichTextBox.GetLineFromCharIndex方法的典型用法代碼示例。如果您正苦於以下問題:C# RichTextBox.GetLineFromCharIndex方法的具體用法?C# RichTextBox.GetLineFromCharIndex怎麽用?C# RichTextBox.GetLineFromCharIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.GetLineFromCharIndex方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Button1_Click
// This method demonstrates retrieving line numbers that
// indicate the location of a particular word
// contained in a RichTextBox. The line numbers are zero-based.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
// Reset the results box.
TextBox1.Text = "";
// Get the word to search from from TextBox2.
string searchWord = TextBox2.Text;
int index = 0;
//Declare an ArrayList to store line numbers.
System.Collections.ArrayList lineList = new System.Collections.ArrayList();
do
{
// Find occurrences of the search word, incrementing
// the start index.
index = RichTextBox1.Find(searchWord, index+1, RichTextBoxFinds.MatchCase);
if (index!=-1)
// Find the word's line number and add the line
// number to the arrayList.
{
lineList.Add(RichTextBox1.GetLineFromCharIndex(index));
}
}
while((index!=-1));
// Iterate through the list and display the line numbers in TextBox1.
System.Collections.IEnumerator myEnumerator = lineList.GetEnumerator();
if (lineList.Count<=0)
{
TextBox1.Text = searchWord+" was not found";
}
else
{
TextBox1.SelectedText = searchWord+" was found on line(s):";
while (myEnumerator.MoveNext())
{
TextBox1.SelectedText = myEnumerator.Current+" ";
}
}
}