简体   繁体   English

如何处理TableLayoutPanel单元格中的MouseDoubleClick?

[英]How to handle a MouseDoubleClick in a cell of a TableLayoutPanel?

I have a TableLayoutPanel in a WinForm . 我在WinForm有一个TableLayoutPanel The cells of the TableLayoutPanel are populated dynamically with custom UserControls . TableLayoutPanel的单元格使用自定义UserControls动态填充。 Each of this UserControls is used to display a Chart (with the DevExpress Charting Tools). 每个UserControls都用于显示Chart (使用DevExpress图表工具)。 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 . 因此,我尝试使用MouseDoubleClick-Event

I first used the Designer to assign the MouseDoubleClick-Event to the TableLayoutPanel . 我首先使用DesignerMouseDoubleClick-Event分配给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. 一旦其中包含UserControl ,就不会再触发/捕获(?)事件。

I tried to set the event to the whole UserControl (in its Designer-View by defining its MouseDouybleClick-Event ). 我试图将事件设置为整个UserControl (在其Designer-View通过定义其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 . 实际上双击的控件会触发MouseDoubleClick事件。

If you tried to double-click on one of your UserControls, then it's the UserControl that will fire the event. 如果您尝试双击其中一个UserControl,则将触发该事件的是UserControl。

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). 由于UserControl上的Chart控件具有DockStyle属性为Fill ,因此实际上是双击了Chart控件(因为UserControl根本不可见)。

What you could do is to forward the event to the parent control (your UserControl): 您可以做的是将事件转发到父控件(您的UserControl):

YouUserControl.cs: 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 . 注意:实际上,创建一个只包含一个带有DockStyle.Fill控件的UserControl有点奇怪。 What didn't you use the Chart control directly on your TableLayoutPanel ? 您没有在TableLayoutPanel上直接使用Chart控件吗? 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 ). 如果是因为您在UserContorl中具有其他方法/属性,则可能要从Chart控件继承UserControl(如果未sealed )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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