首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >datagridviewTextBoxCell Vb.net中带有第一行下划线的多行文本

datagridviewTextBoxCell Vb.net中带有第一行下划线的多行文本
EN

Stack Overflow用户
提问于 2013-02-19 21:49:21
回答 1查看 364关注 0票数 0

我可以在插入时使用Environment.NewLine在datagridViewtextboxcell中添加多行文本。但是我想在第一行加上下划线。那么我如何在vb.net中实现这一点呢?

现在,我正在处理DGV的paint方法,用于以两种颜色显示日期格式(如第一列)。

请找到附件中的图片,

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-19 22:29:25

我在回答我自己的问题。处理DataGridView1_CellPainting并为特定的单元格/列调用此方法。首先,分离字符串,并使用TextRenderer类在新位置渲染它两次。

我不知道这是不是正确的方法,但它是有效的。

代码语言:javascript
复制
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

谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14959123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档