|
-
Feb 4th, 2011, 10:15 AM
#1
Thread Starter
Frenzied Member
[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:
Dim f As New FontDialog If f.ShowDialog = Windows.Forms.DialogResult.OK Then Me.Lbl.Text = f.Font.Style.ToString End If
which returns an Integer
-
Feb 4th, 2011, 10:42 AM
#2
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.
-
Feb 4th, 2011, 11:00 AM
#3
Thread Starter
Frenzied Member
Re: How to get name of the font Style
When used in this manner its not working
vb Code:
Me.Lbl.Text =f.Font.Size & ", " & f.Font.Style.ToString
-
Feb 4th, 2011, 11:01 AM
#4
Thread Starter
Frenzied Member
Re: How to get name of the font Style
When used in this manner its not working
vb Code:
Me.Lbl.Text =f.Font.Size & ", " & f.Font.Style.ToString
-
Feb 4th, 2011, 11:06 AM
#5
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.
-
Feb 4th, 2011, 11:07 AM
#6
Thread Starter
Frenzied Member
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"
-
Feb 4th, 2011, 11:23 AM
#7
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.
-
Feb 4th, 2011, 11:32 AM
#8
Thread Starter
Frenzied Member
Re: How to get name of the font Style
-
Feb 4th, 2011, 11:39 AM
#9
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|