locked
FonStyle class "bold", "italic" and "underline" RRS feed

  • Question

  • User1754323106 posted

    Hi all,

    I need to create a Font object dynamically and I need my font to be the combo of "bold", "italic" and "underline" depending on which choices the users clicked.

    Currently, I construct my font to be bold by default like so

     Font page_font = new Font(MyFont_String, MyFont_Size, FontStyle.Bold, GraphicsUnit.Pixel);

    I know to make the combo i should do.

    FontStyle.Italic|FontStyle.Bold|FonStyle.Underline

    I'm just not sure how properly concatenate them depending on what the user clicked.

    any suggestion is greatly appreicated.


     

    Tuesday, September 19, 2006 1:37 AM

All replies

  • User-1395392389 posted
     
    Dim font As New Font(System.Drawing.FontFamily.GenericMonospace, 8.0F, FontStyle.Strikeout Or FontStyle.Italic)
    Dim bmp As New Bitmap(100, 100)
    Dim g As Graphics = Graphics.FromImage(bmp)
    g.DrawString("ryoushin", font, Brushes.White, 10.0F, 10.0F)
    bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    g.Dispose()
    bmp.Dispose()

     From the SDK: "Multiple values of the FontStyle enumeration can be combined with the OR operator".

    Hop it helps.

    Thursday, September 21, 2006 8:22 AM
  • User-1395392389 posted
     
    Dim fs As FontStyle = FontStyle.Regular
    If True Then fs = fs Or FontStyle.Underline
    If True Then fs = fs Or FontStyle.Italic
    Dim font As New Font(System.Drawing.FontFamily.GenericMonospace, 8.0F, fs)
    Dim bmp As New Bitmap(100, 100)
    Dim g As Graphics = Graphics.FromImage(bmp)
    g.DrawString("ryoushin", font, Brushes.White, 10.0F, 10.0F)
    bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    g.Dispose()
    bmp.Dispose()

     ...damn I'm fast in cutting & pasting!...

    Hope it helps.

    Thursday, September 21, 2006 8:50 AM