Hi - I'm writing a program the changes what you cut and paste. One problem is that it doesn't delete the text you cut...
This is the function i'm using to delete text..
//Deleting selected text
public string deleteSelected()
{
string ret = "";
string str = textBox1.Text;
MessageBox.Show(str);
for (int i = 0; i <= textBox1.Text.Length - 1; i++)
{
if (!(i >= textBox1.SelectionStart && i < textBox1.SelectionStart + textBox1.SelectionLength))
{
ret += str[i];
}
}
MessageBox.Show(ret);
return ret;
}
and here is the code where i'm using the function:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.A) //Select all
{
textBox1.SelectAll();
}
if (e.Control && e.KeyCode == Keys.C) //Copy
{
Clipboard.SetText(textBox1.SelectedText);
}
if (e.Control && e.KeyCode == Keys.X) //Cut
{
string afterDelete = deleteSelected();
MessageBox.Show(afterDelete);
textBox1.Text = afterDelete;
Clipboard.SetText(textBox1.SelectedText);
}
}
When I run the compiler I receive no errors, but when debugging I get this "Un-handled exception has occurred in your application." it also says "Value cannot be null. Parameter name: text"
I don't know why it thinks the i'm setting the text to null! Please help!
(and if you find a built in function for deleting text - please let me know!)