Windows中的Usercontrol [英] Usercontrol in Windows

查看:97
本文介绍了Windows中的Usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Uc2:

Public void Uc2_Load(...)

{

if(id == 1)

{

message.show(id no is one);

}

else if(id == 2)< br $>
{

message.show(id no is two);

}

else if(id = = 3)

{

message.show(id no is three);

}

}



Uc1:

公共无效Uc1_clicked(...)

{



id = Generatingids();

}



海友........

我有两个用户控件Uc1和Uc2。如果我单击Uc1它会生成id号码。现在我想将此ID传递给Uc2并显示消息.....

Plz帮助我

Uc2:
Public void Uc2_Load(...)
{
if(id==1)
{
message.show("id no is one");
}
else if(id==2)
{
message.show("id no is two");
}
else if(id==3)
{
message.show("id no is three");
}
}

Uc1:
Public void Uc1_clicked(...)
{

id=Generatingids();
}

Hai friends........
I have two user controls Uc1 and Uc2. If i click the Uc1 it generate the id Number.Now i want to pass this id no to Uc2 and display the message.....
Plz help me

推荐答案

这很简单 - 复杂的是两个UC不应该知道另一个的存在。所以你做的是让UC1创建一个由父控件或表单处理的事件,并收集ID并将其传递给UC2的实例。



是的,听起来很复杂,但在实践中真的很容易!请参阅此处:在两种表格之间传递信息,第3部分:儿童与儿童 [ ^ ] - 它谈论表单,但它完全是相同的过程(毕竟,Form只是一个Control的特例)。
It's pretty simple - the complication is that the two UC's shouldn't know about the existence of the other. So what you do is have UC1 create an event which is handled by the parent control or form, and which collects the ID and passes it to the instance of UC2.

Yes, it sound complex, but it's really easy in practice! See here: Transferring information between two forms, Part 3: Child to Child[^] - it talks about forms, but it's exactly the same process (a Form is just a special case of a Control, after all).


这篇关于Windows中的Usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆