简体   繁体   中英

How to handle a MouseDoubleClick in a cell of a TableLayoutPanel?

I have a TableLayoutPanel in a WinForm . The cells of the TableLayoutPanel are populated dynamically with custom UserControls . Each of this UserControls is used to display a Chart (with the DevExpress Charting Tools). The reason behind this is to arrange the charts in several rows and each row contains three columns.

Now since the charts are rather small, I want to give the user the opportunity to maximize each chart by double-clicking on the chart. Therefore I tried to use the MouseDoubleClick-Event .

I first used the Designer to assign the MouseDoubleClick-Event to the TableLayoutPanel . This works fine as long as the cells of the table are empty. As soon as there is a UserControl in it, the event is not fired/captured(?) any more.

I tried to set the event to the whole UserControl (in its Designer-View by defining its MouseDouybleClick-Event ). But it is not captured again :(

What am I doing wrong?

The MouseDoubleClick event is fired for the control that is actually double-clicked .

If you tried to double-click on one of your UserControls, then it's the UserControl that will fire the event.

EDIT:

As your Chart control on your UserControl has the DockStyle property to Fill , then it's actually the Chart control that is double-clicked (as your UserControl is not visible at all).

What you could do is to forward the event to the parent control (your UserControl):

YouUserControl.cs:

    private void chartControl_DoubleClick(object sender, EventArgs e)
    {
        this.OnDoubleClick(EventArgs.Empty);
    }

Note: Actually, it's a bit strange to create a UserControl that only contains one control with DockStyle.Fill . What didn't you use the Chart control directly on your TableLayoutPanel ? If it's because you have additional method/properties in your UserContorl, you may instead want to inherit your UserControl from your Chart control (if it's not sealed ).

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