Hi bucz,
May way to do this is implement the IMessageFilter interface. This allows the application to capture a message before it is dispatched to a control or form. Try something like the following:
Code Snippet
MenuStripP
public partial class Form2 : Form, IMessageFilter
{
public Form2()
{
InitializeComponent();
Application.AddMessageFilter(this);
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("deleteing");
}
private void Form2_Load(object sender, EventArgs e)
{
this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;
}
#region const int WM_KEYDOWN = 0x100;
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_KEYDOWN)
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
if (keyCode == Keys.Delete && (this.ActiveControl is TextBoxBase))
{
SendMessage(this.ActiveControl.Handle, (uint)m.Msg, (int)m.WParam, (int)m.LParam);//delete function in TextBox
return true;
}
}
return false;
}
#endregion
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.RemoveMessageFilter(this);
}
}
Best Regards. Rong-Chun Zhang |