2013-07-03 87 views
0

我正試圖建立一個公司網格從我的數據庫生成FlowLayoutPanel行之間的行

我將自己的流佈局設置爲自頂向下。是否可以在這樣的行之間放置一條線http://data.worldbank.org/country

如果需要,我的代碼發佈在下面。

public void createLinks(string[] groupNames) 
    { 
     for (int i = 0; i < groupNames.Length; i++) 
     { 
      LinkLabel obj = new LinkLabel(); 
      obj.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; 
      obj.LinkColor = Color.Black; 
      obj.Name = groupNames[i]; 
      obj.Text = groupNames[i]; 
      obj.Click += delegate(object sender, EventArgs e) 
      {LinkLabel ss = sender as LinkLabel; 
      frmCompanyReport test = new frmCompanyReport(ss.Name); 
      test.Show(); 
      }; 
      flowLayoutPanel1.Controls.Add(obj); 
     } 
    } 
+0

[在一個FlowLayoutPanel的用戶控件之間調整間距]的可能的複製(http://stackoverflow.com/questions/11330734/adjusting-spacing-between-usercontrols-in-a- FlowLayoutPanel的) – user6807975

回答

1

一個解決方案是使用標籤作爲一條線。將AutoSize設置爲False,將Height設置爲1,將BorderStyle設置爲FixedSingle。然後將寬度設置爲與FlowLayoutPanel相同。

是這樣的:

public void createLinks(string[] groupNames) 
    { 
     for (int i = 0; i < groupNames.Length; i++) 
     { 
      LinkLabel obj = new LinkLabel(); 
      obj.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; 
      obj.LinkColor = Color.Black; 
      obj.Name = groupNames[i]; 
      obj.Text = groupNames[i]; 
      obj.Click += delegate(object sender, EventArgs e) 
      { 
       LinkLabel ss = sender as LinkLabel; 
       frmCompanyReport test = new frmCompanyReport(ss.Name); 
       test.Show(); 
      }; 
      flowLayoutPanel1.Controls.Add(obj); 

      Label line = new Label(); 
      line.AutoSize = false; 
      line.BorderStyle = BorderStyle.FixedSingle; 
      line.Height = 1; 
      line.Width = flowLayoutPanel1.Width; 
      flowLayoutPanel1.Controls.Add(line); 
     } 
    }