1

I have a custom user control that contains a chart element that takes up 80% of the space.

When this is placed in a form, i can click the area not occupied by the chart and the click/mousedown/mouseup events work. But yet when i click in the chart area the mouse events aren't passed through and therefore not triggered.

Is there a global way of doing this without having at add the event function for each control on the form?

    void Drag_MouseDown(object sender, MouseEventArgs e)
    {
        activeControl = sender as UserControl;
        previousLocation = e.Location;
        Cursor = Cursors.SizeAll;
    }

    void Drag_MouseMove(object sender, MouseEventArgs e)
    {
        if (activeControl == null || activeControl != sender)
            return;

        var location = activeControl.Location;
        location.Offset(e.Location.X - previousLocation.X, e.Location.Y - previousLocation.Y);
        activeControl.Location = location;
    }

    void Drag_MouseUp(object sender, MouseEventArgs e)
    {
        activeControl = null;
        Cursor = Cursors.Default;
    }

These are at the moment having to be manually set to both the custom usercontrol and the chart

  • 1
    can you share the code here? – DDave Jun 10 '16 at 10:13
  • I've added the code above. I want to know if there is away of calling these functions whenever one of these mouse events is triggered on any child control on the usercontrol rather than having to set them all up manually. – Ashley Cusack Jun 10 '16 at 10:16
  • where have you assigned this events? – DDave Jun 10 '16 at 10:18
  • I've added them in the design manager properties section. I've found items on overides but can't make any seem to work – Ashley Cusack Jun 10 '16 at 10:20
  • i've also tried using protected override void OnClick(EventArgs e) { MessageBox.Show("Test"); } But again this only works outside of the chart – Ashley Cusack Jun 10 '16 at 10:22

1 Answers1

0

It seems like chart overrides your mouse events. So, you can try to add event listeners to chart as well.

PS: We can assign same method to different listeners.

DDave
  • 608
  • 6
  • 17
  • Is there a global function to do this without having to add the listener to each control? – Ashley Cusack Jun 10 '16 at 10:26
  • It generally happens to be listen but in this case it seems like chart is doing some thing of it's own on those events. so, better we override and do our code. – DDave Jun 10 '16 at 10:33
  • @AshleyCusack refer this too http://stackoverflow.com/questions/1719636/how-to-capture-mousemove-events-beneath-child-controls – DDave Jun 10 '16 at 10:38