我可以在插入时使用Environment.NewLine在datagridViewtextboxcell中添加多行文本。但是我想在第一行加上下划线。那么我如何在vb.net中实现这一点呢?
现在,我正在处理DGV的paint方法,用于以两种颜色显示日期格式(如第一列)。
请找到附件中的图片,

谢谢。
发布于 2013-02-19 22:29:25
我在回答我自己的问题。处理DataGridView1_CellPainting并为特定的单元格/列调用此方法。首先,分离字符串,并使用TextRenderer类在新位置渲染它两次。
我不知道这是不是正确的方法,但它是有效的。
Private Sub CellText_Underline(color As Color, e As DataGridViewCellPaintingEventArgs)
Dim text As String = e.FormattedValue.ToString()
Dim nameParts As String() = text.Split(" ")
Dim topLeft As New Point(e.CellBounds.X, CInt(e.CellBounds.Y + (e.CellBounds.Height / 4)))
Dim arialBold As New Font("Arial", 11, FontStyle.Regular Xor FontStyle.Underline)
TextRenderer.DrawText(e.Graphics, nameParts(0), arialBold, topLeft, color)
Dim topLeft_1 As New Point(e.CellBounds.X, CInt(e.CellBounds.Y + (e.CellBounds.Height / 4) + 5))
Dim s As Size = TextRenderer.MeasureText(nameParts(0), arialBold)
Dim p As New Point(topLeft_1.X, topLeft_1.Y + 12)
Dim arialBold_1 As New Font("Arial", 11, FontStyle.Regular)
TextRenderer.DrawText(e.Graphics, nameParts(1), arialBold_1, p, SystemColors.WindowText)
End Sub谢谢。
https://stackoverflow.com/questions/14959123
复制相似问题