没分了,好有人回答我的问题吗?郁闷中 我的问题是这样的我现在动态在页面上添加一些按钮,那么我怎么知道在生成的按钮中是点了那个呢比如生成 按钮1 按钮2 按钮3 按钮4我随便点,我怎么点了那个,我就是想获取点了哪个,然后把她的背景图片换成其他的图片,搞了几天了,人都快爆了!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在页面上加个按钮,加个TEXT框。private void btn_addButtons_Click(object sender, System.EventArgs e) { // 计数,计算目前是添加的几个按钮 count++; // 计算待添加按钮的位置 int localY = this.btn_addButtons.Height * count; int localX = 10 * count; Button toAddButton = new Button(); // 设置待添加按钮的属性 toAddButton.Name="Button " + count; toAddButton.Text=" 按钮" + count + " "; toAddButton.Location= new Point(localX, localY); // 设置待添加按钮的事件 toAddButton.MouseEnter += new System.EventHandler(this.btn_MouseEnter); toAddButton.MouseLeave += new System.EventHandler(this.btn_MouseLeave); toAddButton.Click += new System.EventHandler(this.btn_Click); // 把控件添加到窗口中 this.Controls.Add(toAddButton); } private void btn_MouseEnter(object sender, System.EventArgs e) { // unboxing Button currentButton = (Button)sender; // 设置鼠标的背景颜色 currentButton.BackColor = Color.Blue;; } private void btn_MouseLeave(object sender, System.EventArgs e) { //unboxing Button currentButton = (Button)sender; // 设置鼠标的背景颜色 currentButton.BackColor = System.Windows.Forms.Control.DefaultBackColor; } private void btn_Click(object sender, System.EventArgs e) { // unboxing Button currentButton = (Button)sender; // 显示点击了哪个按钮 txt_msg.Text = "你点击了" + currentButton.Text; } C# 中委托例子(转) 关于C#生成excel文件的乱码问题 关于timer控件的,大家来帮帮忙啊 键盘事件问题(急) 自动生成的DataSet的xsd文件的问题 我装了vc 2003.net 运行第一个程序 hello怎么不行 是不是设置错了 在C#中,用GetHostAddresses()方法获取到的主机地址有多个,但是有些不是合法的IP,这是怎么回事? 各位,哪位有比较花哨一点的界面程序! 高手推荐几本c#学习的好书!谢谢! 按钮点击事件,调用js写的函数,出错 网站汉化的收费问题 请问在winform里怎么使用框架结构?
{
// 计数,计算目前是添加的几个按钮
count++; // 计算待添加按钮的位置
int localY = this.btn_addButtons.Height * count;
int localX = 10 * count; Button toAddButton = new Button(); // 设置待添加按钮的属性
toAddButton.Name="Button " + count;
toAddButton.Text=" 按钮" + count + " ";
toAddButton.Location= new Point(localX, localY); // 设置待添加按钮的事件
toAddButton.MouseEnter += new System.EventHandler(this.btn_MouseEnter);
toAddButton.MouseLeave += new System.EventHandler(this.btn_MouseLeave);
toAddButton.Click += new System.EventHandler(this.btn_Click); // 把控件添加到窗口中
this.Controls.Add(toAddButton);
} private void btn_MouseEnter(object sender, System.EventArgs e)
{
// unboxing
Button currentButton = (Button)sender; // 设置鼠标的背景颜色
currentButton.BackColor = Color.Blue;;
} private void btn_MouseLeave(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender; // 设置鼠标的背景颜色
currentButton.BackColor = System.Windows.Forms.Control.DefaultBackColor;
} private void btn_Click(object sender, System.EventArgs e)
{
// unboxing
Button currentButton = (Button)sender; // 显示点击了哪个按钮
txt_msg.Text = "你点击了" + currentButton.Text;
}