9
A
回答
21
是的,你可以。
使用TableLayoutPanel的CellPaint事件來測試哪個行/列調用了該事件,然後使用Graphic對象大小來設置該矩形的顏色。
像這樣(爲第一和第三行):
private void Form_Load(object sender, EventArgs e) {
this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint);
}
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
if (e.Row == 0 || e.Row == 2) {
Graphics g = e.Graphics;
Rectangle r = e.CellBounds;
g.FillRectangle(Brushes.Blue, r);
}
}
5
我發現這個答案更容易實現:
這讓我把一個完整的背景色上我的手機。
- 我
TableLayoutPanel
創建Panel
,其中有一個背景色,並
Dock
這Panel
然後就是TableLayoutPanel
細胞具有 背景色。 我的代碼最終看上去像這樣:
Panel backgroundColorPanel = new Panel();
backgroundColorPanel.BackColor = Color.FromArgb(243, 243, 243);
backgroundColorPanel.Dock = DockStyle.Fill;
backgroundColorPanel.Margin = new Padding(0);
backgroundColorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left));
backgroundColorPanel.AutoSize = true;
backgroundColorPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.originalTableLayoutPanel.Controls.Add(backgroundColorPanel, 0, row);
+1
這可行,但在所需的代碼行,內存使用情況或處理器週期方面效率不高。 – 2014-10-23 15:59:14
相關問題
- 1. VS2008 WinForm屬性顏色選擇器對話框已更改
- 2. 着色行
- 3. 着色datagrid行
- 4. tableLayoutPanel列寬
- 5. TableLayoutPanel行和列在運行時
- 6. 着色列表框
- 7. WPF DataGrid行着色
- 8. Primefaces Datatable着色行
- 9. QSqlRelationalTableModel QTableView着色行
- 10. C#DataGridView行着色
- 11. RichTextbox着色行爲
- 12. 爲combobox中的行着色?
- 13. TableLayoutPanel的控件列屬性
- 14. 尊重交替行着色時,DataGridView中的單元格着色
- 15. TableLayoutPanel刪除空行
- 16. asp.net列圖中每列的着色c#
- 17. 在excel中着色多列
- 18. WPF DataGrid列交替着色
- 19. TableLayoutPanel的行高不正確
- 20. 更改TableLayoutPanel的行寬
- 21. Devexpress列標題顏色(每列不同顏色),winform c#
- 22. 包含着色器的着色器?
- 23. 交替着色表格行
- 24. Qt4:對QIcon進行着色
- 25. Android和行星着色
- 26. 動態着色jTable行
- 27. 在netbeans中着色jtable行
- 28. 每行着色NSTableView文本
- 29. Java着色表格行
- 30. ItemsCollection和備用行着色
你要確保你處置刷。將其創建包裝在using(){}語句中,或使用靜態Brushes.Blue。否則,你會泄漏每個油漆的內存。 – Eilon 2010-01-09 04:58:53
感謝提醒,Eilon - 並提及選項使用靜態筆刷。 – 2010-01-09 05:20:05
'Brushes.Blue'是一個靜態屬性,所以我不會處理它,否則下次使用它時可能會失效。 – 2014-11-21 19:14:24