2

I have a Form MainForm which inherits DockContent and even registered the mousedown and keypress event in the initialization of form. But none of these events get triggered and really don't know what could be the reason.

Below is the code :

using WeifenLuo.WinFormsUI.Docking;
public partial class MainForm : DockContent
{

     InitializeComponent();         
}

 private void InitializeComponent()
 {    
    this.Load += new System.EventHandler(this.MainForm_Load);
    this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
    this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp);
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseDown);
 }


}

private void MainForm_MouseDown(object sender, MouseEventArgs e)
{
    Copy.Show(Cursor.Position);
}

On the right or left click on form i want to show context menu with item "Copy". But mousedown event or even the keypress event does not trigger.

giammin
  • 18,620
  • 8
  • 71
  • 89
sia
  • 1,872
  • 1
  • 23
  • 54
  • any news? did you read my updated answer? – giammin Nov 27 '14 at 08:59
  • @giammin - i'm really don't know... why.. it is not capturing mousedown or any keypress event..I read your answer also.. still same... i'm still trying.. – sia Nov 27 '14 at 09:14

1 Answers1

0

The mouse events only work for the top control so they won't fire for the form controls when there is another control on top.

there you can find some workaround:

How do I grab events from sub-controls on a user-control in a WinForms App?

anyway I created a simple winform app with your code and everything works fine so you have definitely something that is swallowing all your events

using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace WindowsFormsApplication2
{
    public partial class Form1 : DockContent
    {
        public Form1()
        {
            InitializeComponent();
            label1.Text = "init";
            KeyPress += MainForm_KeyPress;
            KeyUp += MainForm_KeyUp;
            MouseDown += MainForm_MouseDown;
        }
        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            label1.Text = "MainForm_MouseDown";
        }
        private void MainForm_KeyUp(object sender, KeyEventArgs e)
        {
            label1.Text = "MainForm_KeyUp";
        }
        private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            label1.Text = "MainForm_KeyUp";
        }
    }
}
Community
  • 1
  • 1
giammin
  • 18,620
  • 8
  • 71
  • 89