0

挿入中にEnvironment.NewLineを使用することで、datagridViewtextboxcellに複数のテキストを追加できます。ただし、1行目に下線を付けたいと思います。では、どうすればvb.netでこれを達成できますか

現在、日付形式で日付を2色で表示するためのDGVのペイント方法を処理しています(最初の列のように)。

添付の画像をご覧ください。 ここに画像の説明を入力してください

電子メールとセル番号の最後から2番目の列に、下線を引きます。

ありがとう。

4

1 に答える 1

0

私は自分の質問に答えています。DataGridView1_CellPainting を処理し、特定のセル/列に対してこのメ​​ソッドを呼び出します。最初に文字列を分離し、新しい場所で TextRenderer クラスで 2 回レンダリングします。

これが正しい方法かどうかはわかりませんが、機能します。

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

ありがとう。

于 2013-02-19T14:29:25.383 に答える