To find out the number of lines displayed in the RichTextBox, run the GetLineFromCharIndex method.
private void Form1_Load(object sender, EventArgs e) {
richTextBox1.Text = "Hello, World! \r\n Hello, World!Hello, World!Hello, World!Hello, World!";
}
private void RichTextBox1_TextChanged(object sender, EventArgs e) {
RichTextBox rbox = (RichTextBox)sender;
int len = rbox.TextLength;
int lines;
if (len > 0) {
lines = rbox.GetLineFromCharIndex(len - 1) + 1;
} else {
lines = 0;
}
label1.Text = $"lines:{lines}";
}
see also:
GetCharIndexFromPosition
GetPositionFromCharIndex
There are many messages to provide layout information.
「Edit Control Messages」
https://learn.microsoft.com/en-us/windows/win32/controls/bumper-edit-control-reference-messages
EM_GETLINECOUNT, EM_LINEFROMCHAR, ...etc