Как отловить нажатие ctrl+v ctrl+c ctrl+x key_Press - C#
Формулировка задачи:
Как правильно отловить нажатие ctrl+v ctrl+c ctrl+x в событии key_Press?
я пробую так:
Что-то не получается пока...
private void textBox_ServerIP_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar == (Char)Keys.V) && (ModifierKeys == Keys.Control))
{
textBox_ServerIP.Paste();
e.Handled = true;
}
else if ((e.KeyChar == (Char)Keys.C) && (ModifierKeys == Keys.Control))
{
textBox_ServerIP.Copy();
e.Handled = true;
}
else if ((e.KeyChar == (Char)Keys.X) && (ModifierKeys == Keys.Control))
{
textBox_ServerIP.Cut();
e.Handled = true;
}
}Решение задачи: «Как отловить нажатие ctrl+v ctrl+c ctrl+x key_Press»
textual
Листинг программы
private void textBox_ServerIP_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar == (Char)Keys.V) && (ModifierKeys == Keys.Control))
{
textBox_ServerIP.Paste();
e.Handled = true;
}
else if ((e.KeyChar == (Char)Keys.C) && (ModifierKeys == Keys.Control) )
{
textBox_ServerIP.Copy();
e.Handled = true;
}
else if ((e.KeyChar == (Char)Keys.X) && (ModifierKeys == Keys.Control))
{
textBox_ServerIP.Cut();
e.Handled = true;
}
else if ( (!(Char.IsDigit(e.KeyChar)) && !((e.KeyChar == '.') && (textBox_ServerIP.Text.Length != 0))) )
{
if (e.KeyChar != (char)Keys.Back)
e.Handled = true;
}
}