C# static函数调用非static函数 改变控件属性 急!!!!

xds1022 2010-09-12 12:20:24
在winform窗体类form1中

void Start()
{
this.button1.enable = true;
}
//下面的这个Start方法已经在程序中调用了


在下面的静态函数中想把 控件button1的enable属性 设置为false
static void SetButtonAttribute()
{
this.button1.enable = false; //如果这样调用不行,因为在静态的函数中 不能引用this

//现在想实例化一个form1的类
form1 frm = new form1();
frm.button1.enable = false;

// 这样还是不行,因为frm.button1与上面的this.button1不同,达不到改变控件button1属性的效果

}

希各位大虾指点!!
...全文
481 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Peter200694013 2010-09-12
  • 打赏
  • 举报
回复
static void SetButtonAttribute(form1 frm )
{
frm.button1.enable = false;
}


ckl881003 2010-09-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peter200694013 的回复:]

static void SetButtonAttribute(form1 frm )
{
frm.button1.enable = false;
}
[/Quote]
这样就行了
xds1022 2010-09-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peter200694013 的回复:]
static void SetButtonAttribute(form1 frm )
{
frm.button1.enable = false;
}
[/Quote]

在后台的DLL中(另外的一个类库中)注册事件,在前端的界面层引发下面的事件
static void SetButtonAttribute(object sender, System.EventArgs e)
{}
所以不能传递参数的形式,请问在后台中要怎样注册事件,才能在前端调用这个form1参数,
sender转化,好像不行吧.
xds1022 2010-09-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peter200694013 的回复:]
static void SetButtonAttribute(form1 frm )
{
frm.button1.enable = false;
}
[/Quote]

请问我怎么调用这个SetButtonAttribute方法
例如在方法
static A ()
{
///.....
SetButtonAttribute(new form1());
}
//这样好像不行 new form1()不能达到效果
xds1022 2010-09-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ckl881003 的回复:]
引用 1 楼 peter200694013 的回复:

static void SetButtonAttribute(form1 frm )
{
frm.button1.enable = false;
}

这样就行了
[/Quote]

怎么调用在其它方法中调用 static SetButtonAttribute方法
如果是这样的SetButtonAttribute(new form1());调用的话 还是不行哦
xds1022 2010-09-12
  • 打赏
  • 举报
回复
在后台的DLL中(另外的一个类库中)注册事件,在前端的界面层引发下面的事件
static void SetButtonAttribute(object sender, System.EventArgs e)
{}
所以不能传递参数的形式,请问在后台中要怎样注册事件,才能在前端调用这个form1参数,
sender转化,好像不行吧.

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧