Answered by:
Painting in TableLayout

Question
-
How can I paint (fill with green for example) at a specific cell in a Tablelayout? Thanks.Sunday, September 23, 2012 10:19 AM
Answers
-
I added Textboxes to every cell in an existing TableLayout and then made one cell green.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TableLayoutPanel1.Visible = True Dim newRowStyle As RowStyle = New RowStyle() newRowStyle.SizeType = SizeType.Absolute newRowStyle.Height = 30 ' Add controls to the new row Dim row As Integer Dim column As Integer For row = 0 To (TableLayoutPanel1.RowCount - 1) For column = 0 To (TableLayoutPanel1.ColumnCount - 1) Dim textBox As TextBox = New TextBox() textBox.Text = String.Format("TextBox({0}, {1}) ", column, row) TableLayoutPanel1.Controls.Add(textBox, column, row) Next column Next row Dim rownumber = 2 Dim colnumber = 3 Dim cell As Control = _ TableLayoutPanel1.GetControlFromPosition(colnumber, rownumber) cell.BackColor = Color.Green End Sub
jdweng
- Marked as answer by elenial Tuesday, September 25, 2012 8:09 PM
Sunday, September 23, 2012 12:49 PM
All replies
-
I added Textboxes to every cell in an existing TableLayout and then made one cell green.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TableLayoutPanel1.Visible = True Dim newRowStyle As RowStyle = New RowStyle() newRowStyle.SizeType = SizeType.Absolute newRowStyle.Height = 30 ' Add controls to the new row Dim row As Integer Dim column As Integer For row = 0 To (TableLayoutPanel1.RowCount - 1) For column = 0 To (TableLayoutPanel1.ColumnCount - 1) Dim textBox As TextBox = New TextBox() textBox.Text = String.Format("TextBox({0}, {1}) ", column, row) TableLayoutPanel1.Controls.Add(textBox, column, row) Next column Next row Dim rownumber = 2 Dim colnumber = 3 Dim cell As Control = _ TableLayoutPanel1.GetControlFromPosition(colnumber, rownumber) cell.BackColor = Color.Green End Sub
jdweng
- Marked as answer by elenial Tuesday, September 25, 2012 8:09 PM
Sunday, September 23, 2012 12:49 PM -
Can I use the Paint method instead of that?Sunday, September 23, 2012 2:57 PM
-
- Proposed as answer by Mark Liu-lxfModerator Monday, September 24, 2012 5:53 AM
Sunday, September 23, 2012 3:05 PM