locked
Setting Font Size and Font Type in Graphics.Drawstring Method RRS feed

  • Question

  • hi 

    i m using the following code to print date and time:

     Dim s As String = "Print Date: " & Now.ToLongDateString + " " + Now.ToShortTimeString

      e.Graphics.DrawString(s, dgv.Font, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top + e.MarginBounds.Height + 7)

    How to set the font size to 12 and font type to Arial??

     


    Rismiya Nasrudeen
    Wednesday, December 8, 2010 11:08 AM

Answers

  • Construct the font you need and pass it instead of dgv.Font
    MCTS, CodeProject MVP 2008
    • Marked as answer by Jing0 Friday, December 17, 2010 10:40 AM
    Wednesday, December 8, 2010 11:52 AM
  • Dim style As New DataGridViewCellStyle()
    style.Font = New Font(dataGridView.Font, FontStyle.Bold)
    dataGridView.Rows(0).DefaultCellStyle = style

    • Marked as answer by Jing0 Friday, December 17, 2010 10:40 AM
    Wednesday, December 8, 2010 4:20 PM

All replies

  • Construct the font you need and pass it instead of dgv.Font
    MCTS, CodeProject MVP 2008
    • Marked as answer by Jing0 Friday, December 17, 2010 10:40 AM
    Wednesday, December 8, 2010 11:52 AM
  • Dim style As New DataGridViewCellStyle()
    style.Font = New Font(dataGridView.Font, FontStyle.Bold)
    dataGridView.Rows(0).DefaultCellStyle = style

    • Marked as answer by Jing0 Friday, December 17, 2010 10:40 AM
    Wednesday, December 8, 2010 4:20 PM