/// <summary>
/// 自動產生物件
/// </summary>
private void SetTabControlDefault()
{
int pagecount =10;
int count = 30;
//TabPage(1~10)自動產生
for (int J = 0; J < pagecount; J++)
{
TabPage tbpage = new TabPage();
tbpage.Location = new System.Drawing.Point(4, 24);
tbpage.Padding = new System.Windows.Forms.Padding(3);
tbpage.Size = new System.Drawing.Size(685, 539);
tbpage.Name = "tp" + J.ToString();
tbpage.Text = J.ToString();
tbpage.TabIndex = J;
tbpage.AutoScroll = true; //是否自動顯示捲軸
tbpage.UseVisualStyleBackColor = true;
tabControl1.Controls.Add(tbpage);
//label.textbox 每個tabPage各產生30個
for (int i = 0; i < count; i++)
{
Label lb = new Label(); //label
lb.Name = "lb" + tbpage.Name.ToString() + i.ToString();
lb.Text = "lb" + tbpage.Name.ToString() + i.ToString();
lb.AutoSize = true;
lb.Location = new System.Drawing.Point(15, 10 + i * 30);
lb.Size = new System.Drawing.Size(150, 25);
lb.TabIndex = i;
tbpage.Controls.Add(lb);
TextBox txt = new TextBox(); //textbox
txt.Name = "txt" + tbpage.Name.ToString() + i.ToString();
txt.Location = new System.Drawing.Point(150, 10 + i * 30);
txt.Size = new System.Drawing.Size(150, 25);
txt.TabIndex = i;
tbpage.Controls.Add(txt);
}
}
}
2012年8月6日 星期一
[C#]自動產生物件
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言