First THANKS to all who responded. My What I Tried Code was VB.Net and way over complicated.
So I decided to start kind of from scratch. Looked at a few Code Project articles.
The suggestion to use
var lineCount = rtbInfo.Lines.Count();
was less work but I wanted to know how to capture this "\n" in the RichTextBox.
While this code works it presented problems of how to deal with setting the
RTB to Read Only = true. This led to learning how to work with ProcessCmdKey.
The two variables tot and totE the first is use when entering NEW data the other when doing an EDIT
The value 127 is the max number of characters permitted in the RTB.
here is the code suggestions welcomed this is my first C# application.
I do NOT understand what the "c" does in this line of code.
Quote:
foreach (char c in rtbInfo.Text)
private void rtbInfo_TextChanged(object sender, EventArgs e)
{
vbCr = 0;
if (rtbInfo.Text.Contains("\n"))
{
char[] carReturn = {'\n'};
foreach (char c in rtbInfo.Text)
{
if (carReturn.Contains(c))
{
vbCr += 1;
}
}
}
if (frmStart.doWhat == 3)
{
totE = rtbInfo.TextLength;
tbMessage.Text = "Enter " + (127 - totE) + " more characters & " + (4 - vbCr) + " Lines";
}
if (frmStart.doWhat == 1)
{
tot = rtbInfo.TextLength;
tbMessage.Text = "Enter " + (127 - tot) + " more characters & " + (4 - vbCr) + " Lines";
}
if (tot == 127 | totE == 127)
{
rtbInfo.ReadOnly = true;
tbMessage.Text = "UP Arrow Key to Edit NOTES";
}
if (vbCr == 4)
{
rtbInfo.ReadOnly = true;
tbMessage.Text = "Only 4 Lines UP Arrow Key to Edit";
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Up)
{
rtbInfo.ReadOnly = false;
tbMessage.Text = "Edit Additional Notes";
SendKeys.Send("{BACKSPACE}");
rtbInfo.Focus();
return true;
}
else
{
if(vbCr ==4 | tot == 127)
{
tbMessage.Text = "Press UP Arrow Key to Edit";
}
return base.ProcessCmdKey(ref msg, keyData);
}
}