Results 1 to 3 of 3

Thread: [2008] How do I change a text boxs font size?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    30

    [2008] How do I change a text boxs font size?

    Code:
    TextBox1.Font.Size.Equals(1)
    Whats wrong?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: [2008] How do I change a text boxs font size?

    textbox1.font = new font(textbox1.font.name, 10, textbox1.font.style)

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

    Re: [2008] How do I change a text boxs font size?

    Quote Originally Posted by Zezombia
    Code:
    TextBox1.Font.Size.Equals(1)
    Whats wrong?
    Font objects are immutable, which means that, once you have created them, you cannot change them. If you want to change anything about a Font you must create a new Font object with the desired configuration, as .paul. has demonstrated.

    Your code would be wrong anyway, even if Fonts were mutable. The correct code in that case would have been:
    vb.net Code:
    1. TextBox1.Font.Size = 1
    What you're code is doing is testing whether the current Size is equal to 1. That expression will return either True or False, which you're obviously ignoring anyway. Your code would only be used where you wanted to test the current Size of the Font, e.g.
    vb.net Code:
    1. If TextBox1.Font.Size.Equals(1) Then
    2.     'The Font Size is 1.
    3. End If
    That said, you wouldn't use the Equals method to do that anyway, as you simply do this:
    vb.net Code:
    1. If TextBox1.Font.Size = 1 Then
    2.     'The Font Size is 1.
    3. End If
    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

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