winform类型装换Unable to cast object of type'X'to type'System.Windows.Forms.Button'

心灵彩虹 2011-02-10 09:40:07
当运行到下面的程序时:

if (((Button)sender).Text == "启用(&F)")
{
ci.delmode = "1";
}
报错:

Unable to cast object of type 'X.001' to type 'System.Windows.Forms.Button'.

注明:X.001是页面的名称,请高手帮忙。
...全文
2414 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
心灵彩虹 2011-02-10
  • 打赏
  • 举报
回复
分还是要给大家的,马上给。
心灵彩虹 2011-02-10
  • 打赏
  • 举报
回复
呵呵,自己解决了,不是那个原因,事件里面的方法写错了,哎,自己不细心啊。
hitlcyu19 2011-02-10
  • 打赏
  • 举报
回复
没错
[Quote=引用 2 楼 wuyq11 的回复:]

sender不是button
FindControl("") as Button
[/Quote]
wuyq11 2011-02-10
  • 打赏
  • 举报
回复
自己的上下文环境
心灵彩虹 2011-02-10
  • 打赏
  • 举报
回复
能不能写详细些,谢谢![Quote=引用 3 楼 wuyq11 的回复:]
this.Control("") 查找
[/Quote]
wuyq11 2011-02-10
  • 打赏
  • 举报
回复
this.Control("") 查找
wuyq11 2011-02-10
  • 打赏
  • 举报
回复
sender不是button
FindControl("") as Button
bdmh 2011-02-10
  • 打赏
  • 举报
回复
你这个sender是什么,不是button把,而是指向的X.001页面

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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