private void GenerateTable(int columnCount, int rowCount,string allignment) { int count=0; int width = 0; int height = 0; int btncount = 1; //Clear out the existing controls, we are generating a new table layout tableLayoutPanel1.Controls.Clear(); //Clear out the existing row and column styles tableLayoutPanel1.ColumnStyles.Clear(); tableLayoutPanel1.RowStyles.Clear(); //Now we will generate the table, setting up the row and column counts first tableLayoutPanel1.ColumnCount = columnCount; tableLayoutPanel1.RowCount = rowCount; #region AllignMentofButtonIntableLayoutPanel for (int x = 0; x < columnCount; x++) { if (x == 0) { tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); } width += 120; ////First add a column for (int y = 0; y < rowCount; y++) { //Next, add a row. Only do this when once, when creating the first column if (x == 0) { tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); } pnelLayout[count] = new Panel(); btn[count] = new Button(); btn[count].Height = 60; btn[count].Width = 120; btn[count].Text = data[count]; btn[count].Name = count.ToString(); btn[count].Height = 60; btn[count].Width = 120; pnelLayout[count].Width = 120; pnelLayout[count].Height = 60; //Get the btnName from Configuration windows and check the btnName with Description if (dtButtonName.Rows.Count > 0) { //Check for the same btn text Name,if it is true change the colour for (int i = 0; i < dtButtonName.Rows.Count; i++) { //Check for btnName and btnCount Index if (data[count] == dtButtonName.Rows[i]["BtnName"].ToString() && (btncount - 1).ToString() == dtButtonName.Rows[i]["BtnIndex"].ToString()) btn[count].BackColor = Color.WhiteSmoke; else if (btn[count].BackColor == Color.WhiteSmoke) { } else btn[count].BackColor = Color.LightGreen; } } else { btn[count].BackColor = Color.LightGreen; } btn[count].TextAlign = ContentAlignment.MiddleCenter; btn[count].FlatStyle = FlatStyle.Popup; btn[count].MouseDown += new MouseEventHandler(Annaunciator_Window_MouseDown); btn[count].ContextMenuStrip = contextMenuStrip1; pnelLayout[count].Controls.Add(lblCorner[count]); pnelLayout[count].Controls.Add(btn[count]); } } #endregion }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)