開発環境 メモ帳
実行環境 Windows 7 Home Premium (32bit)

参考

FormTest3.cs
using System;
using System.Drawing;
using System.Windows.Forms;
 
public class Form1 : Form
{
	private TextBox[] arTextBox;
	private Label[] arLabel;
	private int row = 5;
 
	public Form1()
	{
		InitializeComponent();
	}
 
	private void InitializeComponent()
	{
		ClientSize = new Size(210, 210);
		Text = "FormTest3";
 
		arTextBox = new TextBox[row];
		arLabel = new Label[row];
		SuspendLayout();
 
		for (int i = 0; i < row; i++) {
			int y = 30 + 25 * i;
 
			TextBox tb = new TextBox();
			tb.Font = new Font("", 12f);
			tb.Location = new Point(5, y);
			tb.Size = new Size(100, 25);
			arTextBox[i] = tb;
 
			Label la = new Label();
			la.BorderStyle = BorderStyle.Fixed3D;
			la.Font = new Font("", 16f);
			la.Location = new Point(105, y);
			la.Name = "Label" + i.ToString();
			la.Size = new Size(100, 25);
			la.Text = "00:00:00";
			la.TextAlign = ContentAlignment.MiddleCenter;
			la.Click += new EventHandler(label_Click);
			arLabel[i] = la;
		}
 
		Controls.AddRange(arTextBox);
		Controls.AddRange(arLabel);
		ResumeLayout(false);
	}
 
	private void label_Click(object sender, EventArgs e)
	{
		MessageBox.Show(((Label)sender).Name);
	}
}
 
static class Program
{
	[STAThread]
	static void Main()
	{
		Application.EnableVisualStyles();
		Application.SetCompatibleTextRenderingDefault(false);
		Application.Run(new Form1());
	}
}
 
最終更新:2014年09月11日 19:54