我用循环手动生成按钮(可以自定义横列的个数自动生成)并且放到泛型集合里list<button>里
我想对list里所有的按钮进行操作 (这些操作都要在属性中实现和操作)
例如:我想改变每个按钮上文字的位置 。
谁有好的方法
最好能给段代码
我想好久都没想出来
我想对list里所有的按钮进行操作 (这些操作都要在属性中实现和操作)
例如:我想改变每个按钮上文字的位置 。
谁有好的方法
最好能给段代码
我想好久都没想出来
解决方案 »
- 急急急!!!怎样用return返回多个数据!请高手帮忙
- winform一个错误,求修改
- socket 能传 int long等类型的数据吗
- 资源文件的问题: 编译可以通过,但是在运行时会发生错误,错误提示没有把资源文件嵌入到程序中去。请各位指点指点。
- 高分求在.net 2005 - pocket pc的仿真器中 连接 Sql 2000 的实例,分不够可以再加!
- [没有分了,以后补!]再请前辈指教!
- C# 如何转码?
- c# 查询 EXCEL 中的部分列
- 请问如何让DataSet中的一列数据在DataGridView显示时划分到几个不同的列中(根据另一列的数值)?
- 关于Excel导出错误的问题。求大神帮忙,在线等待啊。。。。。。
- 加载的DLL控件,如何激活事件?
- 关于.net中后台操作时间过长,而造成的超时怎么解决!
就是要找到list里所有的按钮 怎么能实现
设置按钮的X,Y坐标和设置按钮上面的字
然后添加到窗体里面
对于公共的属性,可以用FOR 或者FOREACH做个循环操作,对每个BUTTON属性进行设置
如果需要对某个特别的BUTTON设置其属性,就在循环里面做个IF判断,或者直接制定到某个BUTTON(LIST(INDEX)用IF判断,不用循环
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace buttoncontrol
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ Button b = new System.Windows.Forms.Button();
//
// button1
//
b.Location = new System.Drawing.Point(61, 105);
b.Name = "button1";
b.Size = new System.Drawing.Size(75, 23);
b.TabIndex = 0;
b.Text = "button1";
b.UseVisualStyleBackColor = true;
this.Controls.Add(b); Button c = new System.Windows.Forms.Button();
//
// button1
//
c.Location = new System.Drawing.Point(200, 105);
c.Name = "button2";
c.Size = new System.Drawing.Size(75, 23);
c.TabIndex = 0;
c.Text = "button2";
c.UseVisualStyleBackColor = true;
this.Controls.Add(c);
Button q =(Button)this.Controls["button1"];
q.Click += new EventHandler(q_Click);
} void q_Click(object sender, EventArgs e)
{
((Button)sender).Text = "second";
}
}
}
btn.Left = 0;
btn.Top = 0;
btn.Width = 0;
btn.Height = 0;
btn.Text = "";
btn.TextAlign = ContentAlignment.MiddleCenter;
this.Controls.Add(btn);
但是我是要对生成后的按钮进行修改我试过用for 和foreach 但是在属性get{}中不能用 如果谁能这样实现最好些个例子试试
用事件我还真没试过,不过在属性中 Button btn = sender as Button 能用??
{
InitializeComponent();
List<Button> buttonList = new List<Button>(); // construct buttons
for (int i = 0; i < 10; i++)
{
Button b = new Button();
b.Text = i.ToString();
this.flowLayoutPanel1.Controls.Add(b);
buttonList.Add(b);
} // modify buttons properties
foreach (Button b in buttonList)
{
b.TextAlign = ContentAlignment.MiddleLeft;
}
}不知道LZ是不是想要这样的效果