Einar,
You don't need the conversion:
switch(e.KeyChar)
case (char)(Keys.ControlKey & Keys.V):
Should do.
Update: It doesn't.
I'm afraid you should know the code it produces (22):
switch(e.KeyChar)
case (char)22:
However case in .Net is not as flexible as the one in VFP. Probably a series of if() would do better. ie:
if (Control.ModifierKeys == Keys.Control && e.KeyChar == 22)
{
e.Handled = true;
((Control)sender).Text = "Ctrl+V pressed";
}
Cetin
>I found that I can use Convert.ToInt32() on e.KeyChar and that returns 22 (like Eric said) for ctrl+v. The only problem is that I can check for that in the switch statement because you can only switch on one variable type at a time , and I am switching on a char type. I can either change my switch to switch on an int or add an additional if to check if Convert.ToInt32(e.KeyChar) is equal to 22. I think the rest of tis will be easy.
>
>Thank you both for taking the tie to help me.
>
>Einar
>
>>>Does
Ctrl+V count as one keypress or two keypresses?
>>>Considder the following code that I have in my OnKeyPress
>>>
>>>protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
>>>{
>>> switch(e.KeyChar)
>>> {
>>> case '\b':
>>> case '0':
>>> case '1':
>>> case '2':
>>> case '3':
>>> case '4':
>>> case '5':
>>> case '6':
>>> case '7':
>>> case '8':
>>> case '9':
>>> {
>>> e.Handled = false;
>>> }break;
>>>// case System.Windows.Forms.Keys.ControlKey + System.Windows.Forms.Keys.V:
>>>// {
>>>// System.Windows.Forms.MessageBox.Show("ctrl+v");
>>>// e.Handled = false;
>>>// }break;
>>> default:
>>> {
>>> e.Handled = true;
>>> }break;
>>> }
>>>}
>>>
>>>I have commented out some of the code above, because it doesn't compile. Any hints regarding how I can allow paste would be appreciated.
>>>
>>>Thanks,
>>>Einar
>>
>>Einar,
>>If you're using KeyPressEventArgs then it's a single value of keycode (like asc() in VFP).
>>
>>
>>if (e.KeyChar == 'V') // Shift+v is upper V assuming caps is off
>>
>>With KeyEventArgs you've both the KeyCode and modifiers. ie:
>>
>>if (e.KeyCode == Keys.V && e.Shift)
>>
>>Cetin