DJ메탈짱™의 Free Style

[C#, Winform, 윈폼] TableLayoutPanel, 설정된 row&column에 따라 자동생성, 컨트롤 추가 본문

일(job)/MS(Microsoft)

[C#, Winform, 윈폼] TableLayoutPanel, 설정된 row&column에 따라 자동생성, 컨트롤 추가

뽀&쏭 2016. 1. 7. 13:18



/// <summary>

/// 1.설정된 row, column 따라 테이블 레이아웃 그려주기.

/// 2.xml결과값에 따라 해당 영역의 속성값확인.

/// 3.해당 클래스의 시설물,Seat 등의 속성에 따른 아이콘 & 툴팁 설정.

/// </summary>

/// <param name="columnCount"></param>

/// <param name="rowCount"></param>

private void SeatGenerateTableLayOut(int columnCount, int rowCount)

{

//Clear out the existing controls, we are generating a new table layout

keTableLayoutPanel1.Controls.Clear();

 

//Clear out the existing row and column styles

keTableLayoutPanel1.ColumnStyles.Clear();

keTableLayoutPanel1.RowStyles.Clear();

 

//Now we will generate the table, setting up the row and column counts first

keTableLayoutPanel1.ColumnCount = columnCount;

keTableLayoutPanel1.RowCount = rowCount;

 

for (int x = 0; x < columnCount; x++)

{

//First add a column

//컬럼대상개수에 따라 keTableLayoutPanel  컬럼의 width 설정함.

keTableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / columnCount));

 

for (int y = 0; y < rowCount; y++)

{

//Next, add a row.  Only do this when once, when creating the first column

if (x == 0)

{

keTableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));

}

 

//Create the control, in this case we will add a button

KeLabel cmd = new KeLabel();

 

//cmd.Width = keTableLayoutPanel1.Width / columnCount;

cmd.Text = string.Format("({0}, {1})", x, y);

 

//Finally, add the control to the correct location in the table

keTableLayoutPanel1.Controls.Add(cmd, x, y);

}

}

}