C#循环创建按钮,并可以通过点击判断出是哪个按钮
2017-07-23 12:52
591 查看
吐槽一下,网上找信息真是一门功夫
,做个小学期电影院订票系统(点击座位那种),不想一个个拉按钮就找个循环创建按钮就良莠不齐(我没系统学过C#),然后特么的找到循环创建你就没告诉我怎么监听那个按钮被点击啊好不好!C#双击出来的按钮but_Click函数总不能随便改名吧!
总之现在我终于掌握了这种“核心科技”
,在《ASP.NET项目开发详解》里找到了一句函数。
效果就是这样:
C#源码(就是你项目中的CS源码):
,做个小学期电影院订票系统(点击座位那种),不想一个个拉按钮就找个循环创建按钮就良莠不齐(我没系统学过C#),然后特么的找到循环创建你就没告诉我怎么监听那个按钮被点击啊好不好!C#双击出来的按钮but_Click函数总不能随便改名吧!
总之现在我终于掌握了这种“核心科技”
,在《ASP.NET项目开发详解》里找到了一句函数。
效果就是这样:
C#源码(就是你项目中的CS源码):
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 小学期 { public partial class Computers : Form { string bnID=""; void refurbish() { Button[] btn = new Button[21]; //生成按钮 int j = 0; for (int i = 1; i <= 20; i++)//5列 { if ((i - 1) % 5 == 0) { j++; } btn[i] = new Button(); btn[i].Text = i.ToString(); //设置按钮显示的文字 btn[i].Location = new Point(75 * ((i - 1) % 5) + 30, 35 * j + 50); btn[i].Name = "btn" + i.ToString(); btn[i].Height = 35; //btn[i].BackColor = Color.GreenYellow; this.Controls.Add(btn[i]); //向前台页面添加生成的按钮,from1是你前台页面的ID btn[i].Click += new System.EventHandler(this.btn_Click); } } public Computers() { InitializeComponent(); //for (int i = 0; i < btn.Length; i++) //{ btn[i].Click += new System.EventHandler(this.btn_Click); }//事件归一! } private void btn_Click(object sender, System.EventArgs e) { int i = int.Parse(((Button)sender).Text);//!!!!!!2017.7.23,终于看书找到了===============就是这句 this.Text = i.ToString(); } private void button1_Click(object sender, EventArgs e) { refurbish(); } } }
相关文章推荐
- C#怎么通过一个按钮Button,实现点击这个按钮可以打开一个文件或者文件夹?
- JSP for循环中判断点击的是哪个按钮
- JSP for循环中判断点击的是哪个按钮
- 任意创建偶数个button,每两个button一行,通过点击任何按钮,可以实现相邻按钮间的颜色转换
- 动态创建添加按钮后,解决开始需要点击两次才能触发,之后点击一次就可以了
- 在页面中,我们经常看到,一个button按钮,如果属标点击,就会触发一个窗口的显示,如果二次点击并可以隐藏,那么如何通过JAVA配合html来实现这一功能呢?
- 网络判断网络连接有多种办法,通过C#程序也可以判断与远程主机的连接状态。具体实现方法
- HTML中点击不通过按钮->AJAX异步往后台传值->thinkphp模板中接收->前台HTML得到返回值->经过判断返回值进一步操作
- iOS 循环创建按钮进行点击切换颜色问题
- 带有按钮并且可以执行单击事件的WINFORM窗体,体悟C#的创建过程
- 判断一个给定的字符串通过循环移位是否可以包含另一个字符串
- Unity3D 学习 - 通过C#脚本创建简单的按钮、响应事件
- 多个按钮,jquery选择器 根据value来判断点击了哪个
- 对于循环输出的按钮,使用jquery判断点击的是哪儿个按钮?并使用Ajax提交
- jquery 如何判断哪个按钮被点击了
- iOS--- 动态添加了按钮,绑定同一个点击事件,如何判断点击的是哪个?
- 利用5个标签,4个文本框,2个按钮,自己设计布局实现输入三边求三角形面积。界面如下所示。三角形类的编写可以使用实验4中已经写过的三角形类,当点击“判断三边”时,若能构成三角形,在标签5上显示“可以构成三角形!”,如不能构成三角形,在标签5上显示“不能构成三
- 判断点击了哪个按钮
- C#button之怎样点击按钮使之循环改变背景颜色
- JSP for循环中判断按钮的点击事件