我是新來的人,希望能做得好。如何在合併的菜單條上實施MouseEnter事件
我正在一個文本編輯器(c#)中,我有一個父親的形式,我可以創建幾個孩子的形式。當我打開一個兒童窗體時,他的menuStrip將他父親的菜單條合併爲白色,並且我具有父級menuStrip上的子菜單的所有功能(如某些ToolStripMenuItems)。 我的問題是:我想爲這些ToolStripMenuItems實現MouseEnter事件。此事件將更改toolStripStatusLabel(僅位於父表單中)上的文本,並在其上寫入啓動事件的ToolStripMenuItems的名稱。我可以在父親的菜單條的所有ToolStripMenuItems上輕鬆完成,但是我不知道該怎麼做,才能爲Child's menutrip的所有ToolStripMenuItems啓動此事件。我希望他們也改變ToolStripStatusLabel。
public void ratonencima(object sender, EventArgs e)
{
ToolStripMenuItem aux = (ToolStripMenuItem)sender;
this.toolStripStatusLabel1.Text = aux.Text;
}
這是我從父窗體的ToolStripMenuItem管理MouseEnter事件時調用的方法。我想將事件添加到ToolStripMenuItem中(在執行時),因爲在我創建子表單時他的問題沒有問題,並且他的MenuStrip合併了父類。
我該怎麼辦?
只要不要以爲合併是相關的。您的孩子表單在獲得MouseEnter事件時應該觸發一個事件。您的主窗體可以訂閱它並更新其狀態欄。 –