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. C# windws- Auto increment font size

C# windws- Auto increment font size

Scheduled Pinned Locked Moved C#
csharptutorial
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
    leoiser
    wrote on last edited by
    #1

    I want to get the maximum font size that can fit to a button.I am loading a Button to a panel.its width and height will vary(dynamically based on some calculations).I want to increase to the maximum font size. For example :- Lets assume that Button size is (100,60) and Text is "AC" (only two letters will come). what should be the maximum font size that can fit in this button. if Button size is (150,250) what should be maximum font size that can fit in this button. Please advice Thanks, Ebin

    K 1 Reply Last reply
    0
    • L leoiser

      I want to get the maximum font size that can fit to a button.I am loading a Button to a panel.its width and height will vary(dynamically based on some calculations).I want to increase to the maximum font size. For example :- Lets assume that Button size is (100,60) and Text is "AC" (only two letters will come). what should be the maximum font size that can fit in this button. if Button size is (150,250) what should be maximum font size that can fit in this button. Please advice Thanks, Ebin

      K Offline
      K Offline
      Khaniya
      wrote on last edited by
      #2

      May following code snip helps you

      Graphics g1 = button1.CreateGraphics();

              for (int i = 1; i < 100; i++)
              {
                  SizeF size1 = g1.MeasureString(button1.Text, new Font("Verdana", i, FontStyle.Regular));
                  if (size1.Width > button1.Width)
                  {
                      button1.Font = new Font("Verdana", i - 1, FontStyle.Regular);
                      break;
                  }
              }
      

      :)

      Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please

      L 1 Reply Last reply
      0
      • K Khaniya

        May following code snip helps you

        Graphics g1 = button1.CreateGraphics();

                for (int i = 1; i < 100; i++)
                {
                    SizeF size1 = g1.MeasureString(button1.Text, new Font("Verdana", i, FontStyle.Regular));
                    if (size1.Width > button1.Width)
                    {
                        button1.Font = new Font("Verdana", i - 1, FontStyle.Regular);
                        break;
                    }
                }
        

        :)

        Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please

        L Offline
        L Offline
        leoiser
        wrote on last edited by
        #3

        Not working. Sorry I did not mention the Button is docked to Full; button1.Dock = DockStyle.Fill; I am always getting the button1's width as 2. Thanks for the reply

        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