这可能不是最好的方法,但它对我有用:
//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 });
您可以轻松地将全局事件绑定到流面板中的所有子控件,这对我来说很好用。希望我有所帮助:)