2013-12-19 41 views

回答

0
You can get the location like this 

    private void tableLayoutPanel1_MouseClick(object sender, MouseEventArgs e) 
    { 
     int row = 0; 
     int verticalOffset = 0; 
     foreach (int h in tableLayoutPanel1.GetRowHeights()) 
     { 
      int column = 0; 
      int horizontalOffset = 0; 
      foreach(int w in tableLayoutPanel1.GetColumnWidths()) 
      { 
       Rectangle rectangle = new Rectangle(horizontalOffset, verticalOffset, w, h); 
       if(rectangle.Contains(e.Location)) 
       { 
        Trace.WriteLine(String.Format("row {0}, column {1} was clicked", row, column)); 
        return; 
       } 
       horizontalOffset += w; 
       column++; 
      } 
      verticalOffset += h; 
      row++; 
     } 
    } 
+0

使用此代碼我可以獲取單元格的值,但是在獲得該值後,我想將用戶控件添加到該單元格中。當行和列相同時,如0 0或11,用戶控件在該位置添加,但當行和列的值不同時,它的行爲異常如1 0或0 1.它將用戶用戶添加到此自己的單元希望 –

相關問題