Results 1 to 9 of 9

Thread: [RESOLVED] How to get name of the font Style

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Resolved [RESOLVED] How to get name of the font Style

    I am using an FontDialog to allow the user to select a font, How should it get the font Style form the selected Font.

    Currently i am using

    vb Code:
    1. Dim f As New FontDialog
    2. If f.ShowDialog = Windows.Forms.DialogResult.OK Then
    3. Me.Lbl.Text = f.Font.Style.ToString
    4. End If
    which returns an Integer

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get name of the font Style

    When you say Style, you're talking about Bold, Italic, etc, right?

    I just tried your code and it worked fine for me, as it should do. The FontStyle enumeration is decorated with the Flags attribute, which is specifially intended to display compound values as a list of names. I'd suggest trying that code in a different project and seeing if you get the same result.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: How to get name of the font Style

    When used in this manner its not working

    vb Code:
    1. Me.Lbl.Text =f.Font.Size & ", " & f.Font.Style.ToString

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: How to get name of the font Style

    When used in this manner its not working

    vb Code:
    1. Me.Lbl.Text =f.Font.Size & ", " & f.Font.Style.ToString

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get name of the font Style

    Again, it works fine for me and it should work for you too. Something is wrong with your project or your system.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: How to get name of the font Style

    My Apologizes , it working, I forgot to add .ToString in my actual code

    on the other hand

    Say i have selected "Italic" whose integral value is 1, when i use .ToString on it, then it supposed to return "1" rather then "Italic"

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get name of the font Style

    If you call ToString on a single Enum value then it will always return the text label. If the type is decorated with the Flags attribute then calling ToString on a compound value will return a comma-separated list of text labels. Without the Flags attribute, a compound value will return a number. That's Enums work. If you want an Integer in either of the first two scenarios then you should cast the Enum value as an Integer first, then call ToString on that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: How to get name of the font Style

    Thanks

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] How to get name of the font Style

    Maybe this will help

    Code:
            Dim fd As New FontDialog
            Dim dr As DialogResult = fd.ShowDialog
            If dr = Windows.Forms.DialogResult.OK Then
    
                Dim fsi As Integer = fd.Font.Style 'as a number
                Debug.WriteLine(fsi.ToString)
    
                Dim fs As String = fd.Font.Style.ToString 'as a string
                Debug.WriteLine(fs.ToString)
    
                'the enumeration
                Dim foo As Array = [Enum].GetValues(GetType(FontStyle))
    
                'show all possible combinations
                For x As Integer = 0 To 15
                    Debug.WriteLine(CType(x, FontStyle).ToString)
                Next
                Stop
            End If
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width