Scott, here's an untested code:
private string deletedString=null;
private int deletedStart=0;
private int deletedLength=0;
private void richTextBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.X | Keys.Control:
case Keys.Delete:
if(richTextBox1.SelectionLength>0)
{
deletedString=richTextBox1.SelectedText;
deletedStart=richTextBox1.SelectionStart;
deletedLength=richTextBox1.SelectionLength;
}
else
{
if(richTextBox1.Text!="")
{
deletedString=richTextBox1.Text.Substring(richTextBox1.SelectionStart, 1);
deletedStart=richTextBox1.SelectionStart;
deletedLength=1;
}
}
break;
case Keys.Back:
if(richTextBox1.SelectionLength>0)
{
deletedString=richTextBox1.SelectedText;
deletedStart=richTextBox1.SelectionStart;
deletedLength=richTextBox1.SelectionLength;
}
else
{
if(richTextBox1.SelectionStart>0)
{
deletedString=richTextBox1.Text.Substring(richTextBox1.SelectionStart-1, 1);
deletedStart=richTextBox1.SelectionStart-1;
deletedLength=1;
}
}
break;
case Keys.V | Keys.Control:
if(richTextBox1.SelectionLength>0)
{
deletedString=richTextBox1.SelectedText;
deletedStart=richTextBox1.SelectionStart;
deletedLength=richTextBox1.SelectionLength;
// Added text can be determined here by querying the
clipboard for text data
// addedStart will be richTextBox1.SelectionStart and
addedLength will be the
// length of the text data above, if any.
}
else
{
// Added text can be determined here by querying the
clipboard for text data
// addedStart will be richTextBox1.SelectionStart and
addedLength will be the
// length of the text data above, if any.
}
break;
}
// Trap printable characters here to determine added characters
}