简体   繁体   中英

c# Mouse events through child control

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM