1) Use the RichTextBox.Lines property, and then the Length is the number of lines. This does retrieve all the lines as individual strings, but provided this isn't for latrge amounts of data, you should be ok. The other alternative is to use RichTextBox.GetLineFromChar and provide the total size of the textbox:
int lines = myRichTextBox.GetLineFromCharIndex(myRichTextBox.TextLength) + 1;
labNumberOfLines.Text = lines.ToString();
But that it not as obvious and needs commenting well.
2)Try:
int startOfLine = myRichTextBox.GetFirstCharIndexOfCurrentLine();
int currentLine = myRichTextBox.GetLineFromCharIndex(startOfLine);
myRichTextBox.Select(startOfLine, myRichTextBox.Lines[currentLine].Length);
myRichTextBox.SelectionBackColor = Color.Yellow;
3) Handle the KeyPress event:
private void myRichTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
int startOfLine = myRichTextBox.GetFirstCharIndexOfCurrentLine();
int currentLine = myRichTextBox.GetLineFromCharIndex(startOfLine);
string[] lines = myRichTextBox.Lines;
if (lines.Length > 0)
{
int currentLineLength = lines[currentLine].Length;
if (char.IsLetterOrDigit(e.KeyChar))
{
if (currentLineLength > 72)
{
e.Handled = true;
}
}
}
}
This is just an example: you will need to do more checking!