Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. The reason behind the differences of this.Font = fontdialog1.Font and btnTest.Font

The reason behind the differences of this.Font = fontdialog1.Font and btnTest.Font

Scheduled Pinned Locked Moved C#
comquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lim Yuxuan
    wrote on last edited by
    #1

    This is my first code : private void fontToolStripMenuItem_Click(object sender, EventArgs e) { fontDialog1.ShowDialog();//display the interface to change font this.Font= fontDialog1.Font; } and the result i get for chaning the font size to 14 is this : using this.Font After that, I change the code to this : private void fontToolStripMenuItem_Click(object sender, EventArgs e) { fontDialog1.ShowDialog();//display the interface to change font btnTest.Font= fontDialog1.Font; } and this is what i get for changing the font size to 14 : Using btnTest.Font It seems that by using " this.Font " causes the form and the button to resize in proportion with the Font size of the button. However, by using "btnTest.Font" causes only the font size of the button to change without making the form and button to resize in proportion with the font size of the button. Can anyone please tell me why is that so ?

    G 1 Reply Last reply
    0
    • L Lim Yuxuan

      This is my first code : private void fontToolStripMenuItem_Click(object sender, EventArgs e) { fontDialog1.ShowDialog();//display the interface to change font this.Font= fontDialog1.Font; } and the result i get for chaning the font size to 14 is this : using this.Font After that, I change the code to this : private void fontToolStripMenuItem_Click(object sender, EventArgs e) { fontDialog1.ShowDialog();//display the interface to change font btnTest.Font= fontDialog1.Font; } and this is what i get for changing the font size to 14 : Using btnTest.Font It seems that by using " this.Font " causes the form and the button to resize in proportion with the Font size of the button. However, by using "btnTest.Font" causes only the font size of the button to change without making the form and button to resize in proportion with the font size of the button. Can anyone please tell me why is that so ?

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      The difference is because the Form has its AutoScaleMode property set to Font (which I believe is the VS default for that property). So when you set the Form font size, it triggers an auto scale, but since the Button does not have an AutoScaleMode property, changing the font size does nothing. For what it's worth, if you were using WPF, the button would have resized in both situations. So if you really want that resizing behavior and your requirements allow WPF, I would suggest switching. Otherwise, you may end up having to find some component that does it for you or write all the resizing code yourself.

      L 1 Reply Last reply
      0
      • G Gideon Engelberth

        The difference is because the Form has its AutoScaleMode property set to Font (which I believe is the VS default for that property). So when you set the Form font size, it triggers an auto scale, but since the Button does not have an AutoScaleMode property, changing the font size does nothing. For what it's worth, if you were using WPF, the button would have resized in both situations. So if you really want that resizing behavior and your requirements allow WPF, I would suggest switching. Otherwise, you may end up having to find some component that does it for you or write all the resizing code yourself.

        L Offline
        L Offline
        Lim Yuxuan
        wrote on last edited by
        #3

        Thanks alot! I experimented with the AutoScaleMode property and have a better understanding of the reason.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups