开发者

How to create a direct call between 2 objects

开发者 https://www.devze.com 2023-01-04 21:33 出处:网络
I use C# 2.0 & WinForm for my application. My form has 2 user controls with names: UserControl1 & UserControl2.

I use C# 2.0 & WinForm for my application. My form has 2 user controls with names: UserControl1 & UserControl2.

UserControl1 has a event CriteriaChanged:

public event CriteriaChangedHandler CriteriaChanged;
public delegate void CriteriaChangedHandler(object sender, CriteriaChangedArg e);

UserControl2 has a function:

public void Do(CriteriaChangedArg e){...}

I must use my form like as an intermediate object:

userControl1.CriteriaChanged += userControl1_CriteriaChanged;

private void userControl1_CriteriaChanged(object sender, CriteriaChangedArg e)
{
userControl2.Do(e);
}

How to create a direct call without myForm, when userControl1 raise a event CriteriaChanged, userControl1 will be called with Do() function.

Thanks.开发者_如何学C


Whats wrong with your current method? Seems pretty standard.

If you change the signature UserControl2

public void Do(object sender, CriteriaChangedArg e)

you could do this...

userControl1.CriteriaChanged += userControl2.Do;
0

精彩评论

暂无评论...
验证码 换一张
取 消