---control2.cs-----
namespace go{
public void ttt(){
}
void button3_onclick(...){
ttt();
}
}
}
---control1.cs----
using go;
void button1_onClicke(...){
ttt();
}
namespace go{
public void ttt(){
}
void button3_onclick(...){
ttt();
}
}
}
---control1.cs----
using go;
void button1_onClicke(...){
ttt();
}
但是我不懂 c sharp
无聊的看客,大街遇到抢劫估计你也不会出手阿。
control2 aaa = new control2();aaa.ttt();}
原来所有的语言都一样啊。---control1.cs----
能不能在不知道控件的情况 下,就是不用 using go !一百分肯定是你了。
回答出来再加一百分阿。
我在 pb 的编程,为了提高模块的独立性。经常 是在运行中取得 父窗口,或则是活动窗口,并不固定是那个控件,给他们发送小时的。
比如说 ; parent.event xxxx.
或则
通过一个还是
event(control xxxx)
{ control yyyy
yyyy = xxxx;
yyyy.event(func)
}
先定义一个Delegate,
再用这个Deletaget定义一个事件,
再把你的button1的Click事件钩上这个事件.事定上你可以不定义Delegate,你的button3的Click已对应有一个Deleagte了.
2。实例化在control2的cs文件的类。
3。在Control1的cs设计器中,可以不用手工填写代码。在设计界面中,选中control1,再在属性栏中选中事件,在其Click事件中,实例名称.时间名称。
{
method1(a,b,,,);
method2(a,b,c,,);
。
}contorl1common c = new common;
button.click
{
c.method1(a,b,,,);
}contorl2通上
还可以考虑定义成静态类,这样不用实例化就能用了。
加入我要在 button1 的 clicked 事件中调用 ttt 修改 button3 的某些属性。
哪有怎么办啊?
怎么办啊?
在你的组件中定义:
public delegate void WatchErrorHandler(string errorstr);
public event WatchErrorHandler WatchError; 在要产生的这个事件的地方调用这个事件:
WatchError("出错了");在你使用这个类的地方:
watch1=new watch();//定义一个对象
watch1.WatchError+=new watch.WatchErrorHandler(this.WatchErrorHandler);//将事件处理函数挂钩起来再写你的事件处理函数:
public void WatchErrorHandler(string error)
{
....
}
你在你的应用中创建Control1和Control2的实例。2——
在Control1的Button1的Click事件中作以下操作之一:A——
直接调用ttt:
Control2.ttt(sender,e);
//要求ttt是Public的
//如果在ttt中用到了sender对象,那么,根据需要,修改sender为Control2.Button3B——
发送系统消息,通知Button3被Click(这个比较难)
一个窗口上放置了两个 panel : panel1 和 panle2
然后我 panel1 放了自定义控件 control1
然后我 panel2 放了自定义控件 control2
cotrol1 上包含两个button ,button11,button12
cotrol2 上包含两个button ,button21,button22我现在 button21 自定义一个事件 ttt,来改变 button22 的背景色。 (这个很简单,在同一个 .cs文件中)
我现在想在 button11 的click 事件调用 button21 的 ttt 事件,怎么办。(button11,和button 21 在不同的cs文件中)简单的说就是在不同cs文件的一个类 调用 另 一个类的 方法。希望给出比较好的解决办法。