1: private void bnt_在住房_Click(object sender, EventArgs e)
2: {
3: for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
4: {
5: // Label lb = new Label();//本來是用標簽的,后來發現用按鈕更好。
6: Button lb = new Button(); //聲明一個按鈕型的變量,並實例化;
7: lb.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);//設置控件之間的距離;
8: lb.Width = 80; //設置寬度為80;
9: lb.Height = 80; //設置高度為80;
10: lb.Text = i.ToString("000")+"\n\t標准單人間"; //把循環變量I轉換成字符串類型;
11: lb.BackColor = Color.PowderBlue;//設置控件的背景色;
12: lb.ForeColor = Color.Red; //設置控件的前景色為紅色,也就是文字的顏色;
13: lb.TextAlign = ContentAlignment.TopCenter;
14: //lb.MouseMove += new MouseEventHandler(button_MouseMove);
15: lb.Click += new System.EventHandler(this.clearButton_Click);//用委托實現讓控件響應單擊事件;
16: //lb.MouseLeave += new EventHandler(button_MouseLeave);
17: //lb.Image = Image.FromFile(@"F:/VS2008ImageLibrary/Actions/AddTableHH.bmp");//設置控件的圖片;
18: lb.ImageAlign = ContentAlignment.MiddleCenter;//設置控件上的圖片對齊方式;
19: for (int n = 0; n < 3; n++)
20: {
21: Label lb1 = new Label();
22: lb1.BackColor = Color.SlateGray;
23: lb1.Location = new Point(n * 20 + 7, 60);
24: lb1.Width = 10;
25: lb1.Height = 11;
26: lb.Controls.Add(lb1);
27: }
28: this.flowLayoutPanel1.Controls.Add(lb);
29: }
30: }
下面是效果圖。