2013-05-14 4 views
-1

VS 2010, Windows Form 컨트롤에서 작업하고 있습니다. Invoke FlowLayoutPanel 자식 컨트롤을 클릭했을 때 마우스 조작자

은 내가 동적으로

내 문제는 버튼을 제외하고 아무 곳이나 클릭하면 flowlayout planel에 대한 MouseDownEventhandler 만 실행하는 것입니다 버튼을 추가하는 확장 FlowLayoutPanel을 보유하고 있습니다. When clicked on button the MouseDownEventHandler for the FlowLayoutPanel is not called.

Panel에 추가 된 버튼의 Click 이벤트 핸들러에 배선 기능을 시도했습니다. 하지만 지연으로 인해 문제가 발생하는 것으로 나타났습니다.

아무도 도와 줄 수 있습니까?

답변

0

이것은 propably 최고의 approch 아니지만 나를 위해 작동 :

//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 
    } 
} 

반사 방식 : 당신은 easly 흐름 패널의 모든 자식 컨트롤이 작품에 글로벌 이벤트를 바인딩 할 수 있습니다

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

을 오케이. 희망을 도왔습니다. :)

+0

지금 내 PC에 없으므로 내일 시도해 보겠습니다. – Dinesh