本文整理汇总了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+" ";
}
}
}