Thursday, 8 August 2013

Winform RichTextBox get last character entered using c#

Winform RichTextBox get last character entered using c#

I am using the following code to extract the last character( the character
just typed) using the following code
private string GetTypedChar()
{
string currentChar = "";
int i = rtfText.SelectionStart;
if (i > 0)
{
currentChar = rtfText.Text.Substring(i-1, 1);
MessageBox.Show(i+":"+currentChar);
}
return currentChar;
}
But this is giving me wrong results. If the word entered is "RS" the after
pressing R the message box shows 1: (blank) then on typing S message box
shows 2:R How to achieve this?

No comments:

Post a Comment