-1

当我遇到这个问题时,我正在创建自定义进度条 [WinForm]

**The Structure:**
 -panel 
   -> panel
  so I have panel which inside the panel, there another panel.
**The Goals:**
-I want to use my parent panel as all event handler, 
 while make the child panel have no event at all.
**The Problem:**
- when I press my mouse inside the child panel. the event in parent wont called.
  explanation : -> I still wanted to call parent panel mouse down 
  even if I click on top of my child panel.
4

1 回答 1

1

因此,您希望在单击子面板时在父面板上触发 click 事件。

我可以想到两种方法可以做到这一点。

第一种方法是简单地从 Panel2 的 Click 事件处理方法内部调用 Panel1 的 Click 事件处理方法:

private void panel1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Panel 1 clicked.");
}

private void panel2_Click(object sender, EventArgs e)
{
    this.panel1_Click(sender, e);
}

可能更好的方法是将两个点击事件注册到 1 处理程序方法:

private void panel1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Panel 1 clicked.");
}

然后从表单设计器或手动注册第二个面板的事件:

this.panel2.Click += new System.EventHandler(this.panel1_Click);
于 2012-08-19T22:47:27.040 回答