2013-05-14 30 views
-1

我在VS 2010,Windows窗體控件中工作。調用FlowLayoutPanel Mousedown處理程序時,點擊子控件

我有一個擴展FlowLayoutPanel,我在其中動態添加按鈕

我的問題是,對於MouseDownEventhandler除了flowlayout planel按鈕的任何地方點擊時只執行。 When clicked on button the MouseDownEventHandler for the FlowLayoutPanel is not called

我試着將接線功能添加到Panel的按鈕的Click事件處理程序中。 但我注意到由於我遇到問題而導致延遲。

任何人都可以幫助我嗎?

回答

0

這是propably不是最好的計算策略,但它爲我工作:

//global mouse down handler for controls in flow panel 
private void ControlMouseDown(object sender, MouseEventArgs e) 
{ 
    var control = (Control)sender; 

    if (control.Parent is FlowLayoutPanel) 
    { 
     flowLayoutPanel1_MouseDown(sender, e); //if you have seperate method to handle click on flowpanel otherwise see reflection approach below 
    } 
} 

思考方法:

var onMouseDown = flowLayoutPanel1.GetType().GetMethod("OnMouseDown", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 
onMouseDown.Invoke(flowLayoutPanel1, new object[] { e }); 

您可以全局事件綁定到流面板伊斯利所有子控件和這個作品給我的。希望我幫助:)

+0

我現在不在我的個人電腦上,明天我會試一試 – Dinesh 2013-05-14 16:25:24

相關問題