Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为行着色,添加文本_C#_Winforms - Fatal编程技术网

C# 为行着色,添加文本

C# 为行着色,添加文本,c#,winforms,C#,Winforms,我正试图在Visual Studio Express中创建一个如下所示的表格: 我使用的是表格布局面板。如何使用与图片中类似的灰度样式为tableLayoutPanel中的第一行上色,并可能在第一行的每个单元格中添加一些文本 可以使用此事件方法绘制特定单元格: private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e) { if (e.Row == 0 &&

我正试图在Visual Studio Express中创建一个如下所示的表格:


我使用的是
表格布局面板
。如何使用与图片中类似的灰度样式为
tableLayoutPanel
中的第一行上色,并可能在第一行的每个单元格中添加一些文本

可以使用此事件方法绘制特定单元格:

private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
    if (e.Row == 0 && e.Column == 1)
    {
        e.Graphics.FillRectangle(new SolidBrush(Color.Black), e.CellBounds);
    }
}
只要画出你想要的行中的所有单元格。

为什么不使用一个?
它看起来和你的图片一模一样,你可以在任何单元格中放置文本,在第一列中放置图标,有标题,甚至网格线


将其<代码>视图>代码>属性设置为“代码>视图。详细信息< /代码>以获得所需的Bavior。< /P> < P>您可以考虑使用<代码> DATAGIDVIEW < /代码>,在这里您可以分别对每一行进行着色,并设置每个列的文本。
有关详细信息,您可能需要查看一个
DataGridView
更适合您的样式定制需求:


您可以为所需的任何行设置
DefaultCellStyle
BackgroundColor
ForeColor

ListView控件,选择“详细信息”并在列中填充第一行,它将变成那样。您可能需要修改
Paint
事件,以实现所提供图片中的着色效果。如果使用
DataGridView
,然后只需在
DefaultCellStyle
中调整
ForeColor
BackgroundColor
。我不认为你有一个
TableLayoutPanel
这样的控件。就像@Andrew说的,这正是
DataGridView
的用途。你有什么理由不能用这个吗?我想加上它作为答案,但是Andrew你先到了这里,你应该得到积分。@Andrew winforms中有
System.Windows.Forms.TableLayoutPanel
控件。但是,我完全同意您关于DataGridView的建议。