RichTextBox questions (newbie)

  • Thread starter Thread starter Garry
  • Start date Start date
G

Garry

Hi,
I'm just getting started with C# and .NET, so if this is a stupid
question, I apologise in advance.

Is it possible to get an event on a RichTextBox which when the content
of the RichTextBox is changed, I can find out exactly what happend? The
kind of info I would like is something like, if I typed in 'hello' in
the middle of some preexisting text, I could get Data: 'hello' At
character: 15. The idea being I could then redirect the input into
another RichTextBox and have any number of RichTexBoxes mirroring one
'master' textbox.

Thanks for any help.

Garry
 
Hi Garry,

Try like this:

Put a richtextbox control on the form and add KeyPress and Leave event
handler:

private string enteredText;
//
private void richTB_KeyPress (...)
{
// user is typing -> save this text
enteredText += e.KeyChar.ToString ();
}

private void richTB_Leave (...)
{
// if user has typed something into the richtextbox
if (text != "")
{
// get the location (index) of text
int iTextAt = richTB.Text.IndexOf (text);
// do something with this data (text and iTextAt)
}
}


Hope this helps.
 
Back
Top