怎样在WIinform点击按钮,得到当前点击按钮的Text内容?

bitzhw 2004-12-23 06:02:20
如题
...全文
101 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bitzhw 2004-12-23
  • 打赏
  • 举报
回复
OK。谢了
chenyuming2004 2004-12-23
  • 打赏
  • 举报
回复
private void Butt1_Click(object sender, System.EventArgs e)
{
Button cmd=(Button)sender;
MessageBox.Show(cmd.Text);
}
wnlovezxm 2004-12-23
  • 打赏
  • 举报
回复
((Button)sender).Text
bitzhw 2004-12-23
  • 打赏
  • 举报
回复
public void CreateButton()
{
string[] strxm=new string[3];
strxm[0]="test1";
strxm[1]="test2";
strxm[2]="test3";
for(int i=0;i<strxm.Length;i++)
{
string strtemp=strxm[i];

Button Butt1=new Button();
Butt1.Text =strtemp;

Butt1.Width =80;
Butt1.Height=40;
int leftnum=10+i*80;
int topnum=10;

Butt1.Location = new System.Drawing.Point(leftnum,topnum);
this.Controls.Add(Butt1);
Butt1.Click+=new EventHandler(Butt1_Click);
}
}

这样生成三个按钮,分别为test1,test2,test3
我想:
点击test1,获取test1数据,弹出内容为test1提示框
点击test2,获取test2数据,弹出内容为test2提示框
点击test3,获取test3数据,弹出内容为test3提示框
要怎样实现?在Butt1_Click函数中要怎样做呀?



chaochao830101 2004-12-23
  • 打赏
  • 举报
回复
比如:*****

举个例子.
bitzhw 2004-12-23
  • 打赏
  • 举报
回复
不行,这个按钮是程序生成的,不能用this.Button1.text

kimpankata 2004-12-23
  • 打赏
  • 举报
回复
MessageBox.show(this.Button1.text,"是不是这样的?");

110,555

社区成员

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

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

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