Hallo,將鼠標事件傳遞給基本控件,搜索一個好的解決方案
感謝您的閱讀。我得到的答案真的幫了我,很多!
但對問題。我有UserControl作爲基類。子類在UserControl上添加其控件,讓我們先調用BaseControl和第二個ChildControl。
在BaseControl級別上,我在某些MouseEvent上附加了一些Delegates。
問題是,如果有一個子控件添加到它們,它們將不會觸發。所以我知道我可以從所有的Childrensevent中取出所有Mouseevent,並將它們穿過。但那第一個很髒,一秒不夠。因爲我想要繪製邊框或移動BaseControl。
所以我的問題是真的:有沒有辦法獲得完全訪問在基本控制的MouseEvents,如果有ChildControls添加?
謝謝你很多!
托馬斯
編輯:
這裏是片段,希望大家明白:
public partial class baseControl : UserControl
{
public baseControl()
{
InitializeComponent();
//will not be called
this.MouseUp += delegate(object sender, MouseEventArgs e)
{
// some code
};
}
}
public partial class child : baseControl
{
secretControl childControl;
public child()
{
InitializeComponent();
this.childControl= new secretControl();
this.childControl.Visible = true;
//... ,more
this.forChildUsePanel.Add(this.childControl);
// works fine , as it will be called
this.childControl.MouseUp += delegate(object sender, MouseEventArgs e)
{
// some code
};
}
}
提醒:這是snipptes,所以對於理解目的,削減一些角落。
建議輸入: 我想在添加到BaseControl的每個控件上獲得一些鼠標事件。
托馬斯嗨 - 請提供一個代碼示例,所以我們可以看到你正在試圖做 – 2011-02-02 09:25:41