Results 1 to 7 of 7

Thread: [RESOLVED] Extracting font information

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Resolved [RESOLVED] Extracting font information

    Quick question, is there a more efficient way to determine the properties of a font (I'm basically talking about, bold, italic and underlined states) without having lots of if ...then statements ?

    Basically what I'm getting at is that if I want to alter the bold state of a font how can I do it and leave the other applied states intact.

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

    Re: Extracting font information

    If you're talking about changing the Font of a control then you can't just change individual properties. You have to create a new Font object and assign that to the control's Font property. Pretty much the only way to determine whether a particular style is applied to a Font is with an If and a bitwise And.
    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
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Extracting font information

    Thanks for the help
    Thats the way I'm doing it at the moment it just looks very untidy, I was hoping for some flashy method that would allow me to just toggle the attribute flag that I wanted to change

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

    Re: [RESOLVED] Extracting font information

    You would be able to toggle the particular style you're interested in using a bitwise exclusive or, but you'd still have to create a new Font object. You would toggle the the Bold property like this:
    VB Code:
    1. Dim newFont As New Font(oldFont, oldFont.Style Xor FontStyle.Bold)
    I've never done this myself and I just typed that straight in, so I can't guarantee it but it looks sound to me.
    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

  5. #5
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: [RESOLVED] Extracting font information

    Won't a bitwise XOR make the value end up plain if that style is applied already? 1 Xor 1 = 0 right? isn't Xor only = 1 if the two are opposite?

    Bill

    EDIT - Oh, that's what you wanted to do.
    Last edited by conipto; Nov 18th, 2005 at 03:35 AM.
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: [RESOLVED] Extracting font information

    Looks good to me, I'll try it out tonight when I get home.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: [RESOLVED] Extracting font information

    Just tried it and it works a treat, thanks again for your help JMC.

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