#region constants
private const int WM_COPY = 0x301;
private const int WM_CUT = 0x300;
private const int WM_PASTE = 0x302;
private const int WM_CLEAR = 0x303;
private const int WM_UNDO = 0x304;
private const int EM_UNDO = 0xC7;
private const int EM_CANUNDO = 0xC6;
#endregion
/// <summary>
/// Capture command keys
/// </summary>
/// <param name="msg"></param>
/// <param name="keyData"></param>
/// <returns></returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch(keyData)
{
case Keys.Enter:
if(this._TabOnEnter)
return base.ProcessCmdKey(ref msg, Keys.Tab);
return true;
case Keys.Control | Keys.V:
case Keys.Shift | Keys.Insert:
PostMessage(this.Handle, WM_PASTE, 0, 0);
return true;
case Keys.Control | Keys.C:
case Keys.Control | Keys.Insert:
PostMessage(this.Handle, WM_COPY, 0, 0);
return true;
case Keys.Control | Keys.X:
case Keys.Shift | Keys.Delete:
PostMessage(this.Handle, WM_CUT, 0, 0);
return true;
case Keys.Control | Keys.Delete:
PostMessage(this.Handle, WM_CLEAR, 0, 0);
return true;
case Keys.Control | Keys.Z:
PostMessage(this.Handle, WM_UNDO, 0, 0);
return true;
default:
return base.ProcessCmdKey (ref msg, keyData);
}
}
/// <summary>
///
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_COPY:
if(this._ClipMode == ClipModeConstants.mskExcludeLiterals)
Clipboard.SetDataObject(RemoveFormatCharacters(base.SelectedText).Replace(this._PromptChar, ""));
else
Clipboard.SetDataObject(base.SelectedText.Replace(this._PromptChar, " "));
break;
case WM_PASTE:
case WM_CLEAR:
base.WndProc(ref m);
break;
case WM_CUT:
Clipboard.SetDataObject(base.SelectedText);
this.InsertChararacter(1, "");
break;
//TODO: ova ne ke bide loso da se napravi
case WM_UNDO:
case EM_UNDO:
m.Result = new IntPtr(1);
break;
case EM_CANUNDO:
m.Result = new IntPtr(0);
break;
default:
base.WndProc (ref m);
break;
}
}
I've paste complete working code. You must comment some lines where my special properties are included. I have one problem with this code and if you have a opinion make a post. I don't now how make code part for handling WM_UNDO, EM_UNDO and EM_CANUNDO, to work.