日期:2014-05-18  浏览次数:21048 次

自定义控件如何调用所在窗体的方法
做了一个绘图的自定义控件。放在窗体上之后要求鼠标在控件上移动时在窗体的状态栏上显示当前坐标,请问如何实现。
我在控件中得到了当前的坐标但不知怎么去通知父窗体改变

------解决方案--------------------
usercontrol 中自定义委托,事件,当MouseMove时触发自定义委托事件。
public delegate void MyControlEventHandler(object sender, MyControlEventArgs args);

public event MyControlEventHandler OnButtonClick;



父窗体中 load事件中,
wApp.OnButtonClick +=
new WPFAppSet.MyControlEventHandler(
wApp_OnButtonClick);

private void wApp_OnButtonClick(
object sender,
MyControlEventArgs args)
{
XXX
}