0
votes

I am trying to handle MouseClicks in a custom TabControl. If the user clicks anywhere in the area above the TabPage, I need to handle MouseDown and MouseUp, at least. Obviously, it works clicking on a Tab. But, there seems to be a "Dead" area next to the Tabs, which doesn't fire the MouseDown event.

enter image description here

MouseMove() is firing. Just none of the other Mouse/Click events. I've added a multi-tab selection mode to the TabControl and I want them to be able to click on an individual tab or outside of the tabs to unselect all the "selected" tabs. Need help figuring out the simplest solution.

If you need any more information or clarification, please let know.

EDIT: I was able to use the answer from LarsTech. Thank you, very much.

In my control, I added :

    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);

        Parent.MouseDown += testMousedown;
    }

    private void testMousedown(object sender, MouseEventArgs e)
    {
        if (Bounds.Contains(e.Location))
        {
            MessageBox.Show("tab space clicked");
        }
    }
1

1 Answers

0
votes

Check the MouseDown event of the container:

protected override void OnMouseDown(MouseEventArgs e) {
  base.OnMouseDown(e);

  if (tabControl1.Bounds.Contains(e.Location)) {
    MessageBox.Show("tab space clicked");
  }
}

If the TabControl is in a Panel, then you would have to use the MouseDown event of that Panel.