日期:2014-05-19  浏览次数:20726 次

通过委托在窗体间传递消息必须通过父窗体吗?
结构是这样的

      父窗体
          |
---------------------
|                                     |
子窗体1                       子窗体2
                                      |
                                  子子窗体1  

我在子子窗体1和子窗体1间传递消息,用委托直接传好象传不过去,必须从子子窗体1   传给子窗体2然后传给父窗体再传给子窗体1   ,回传也是一样,这样好象太麻烦了吧?


------解决方案--------------------
参见我的BOLG
http://community.csdn.net/Expert/topic/5486/5486385.xml?temp=.1802484
http://blog.csdn.net/yumanqing/archive/2006/10/13/1333110.aspx

------解决方案--------------------
委托可以做到有返回值?请问
------解决方案--------------------
函数返回什么,委托就返回什么.
public static string getSMSContent(string mobile)
{
  return "11111 ";
}
public delegate string deleSQF(string mobile);
[STAThread]
static void Main(string[] args)
{
  deleSQF mySmsContent = new deleSQF(getSMSContent);
  Console.WriteLine( "返回的值:{0} ",mySmsContent( "sss "));
}

------解决方案--------------------
//Delegate可以在任意2个对象之间使用,

子窗体1:Form
{
public static void OnCall(){...}
}

子子窗体1:Form
{
public EventHandle myHandle;
}

Main()
{
子子窗体1Obj = new 子子窗体1();
子子窗体1Obj.myHandle += new EventHandle(子窗体1.OnCall);
}