0

I try to capture a mouse click event in a form But it does't work

Partial Code as below

public partial class UIMessage : Form
{
    public UIMessage()
    {
    ...
    this.MouseClick += UIMessage_MouseClick;
    this.KeyDown += UIMessage_KeyDown;
    ...
    }

private void UIMessage_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
        Console.WriteLine("Enter");
}

private void UIMessage_MouseClick(object sender, MouseEventArgs e)
{
    Console.WriteLine("Click");
}

Can someone tell me what's wrong with the code?

The Key down event is work well, but mouse click event is not

YS Wang
  • 177
  • 13
  • Oh! I have a Label on the form, is there a way let mouse click event to be captured by form even there are other control on it? – YS Wang Jun 30 '14 at 03:07

1 Answers1

0
private void UIMessage_Click(object sender, MouseEventArgs e)
{
    Console.WriteLine("Click");
}

havent tried, but see if it works. use only Click.

bumbumpaw
  • 2,522
  • 1
  • 24
  • 54
  • The result is same. Now, I know the problem is that there is a Label control on the form, so the Label capture the mouse event. Is there a way can let mouse event transfer to the form at this situation? – YS Wang Jun 30 '14 at 03:12
  • 1
    why not try to put it also on the `Label_Click` ? Im sure its not the best answer. haha Not sure if there's a way like that positioning it after the form layer, something like that. – bumbumpaw Jun 30 '14 at 03:19