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. Magic Button Text Padding

Magic Button Text Padding

Scheduled Pinned Locked Moved C#
graphicstestingbeta-testingregexquestion
2 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.
  • J Offline
    J Offline
    John R Shaw
    wrote on last edited by
    #1

    How does Microsoft calculate the left alignment of text on a button? Test button settings: - All Margins set to 0. - All Padding set to 0. - TextAlign = MiddleLeft. - Button style is Flat. - Setting flat border width to 0 or 1 has no effect on position of text. For pattern illustration: - U = Unknown Pixel (we are not drawing these) - T = Text pixel My drawing: 1. Draw text at x = 0. 2. Draws text 5 pixels from left edge - I can live with that. Pattern: UUUUT Not important: Why is DrawString(...) drawing the text at x=4 instead of x=0? Microsoft drawing: 1. Draws text 11 pixels from left edge. Pattern: UUUUUUUUUUT Important: Where are the extra 6 pixels coming from? I have tried to account for the extra padding by examining the systems information settings. Unfortunately none of those settings explain where the padding is coming from (BorderSize=1, Border3DSize=2). Thanks for any explanation,

    INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

    B 1 Reply Last reply
    0
    • J John R Shaw

      How does Microsoft calculate the left alignment of text on a button? Test button settings: - All Margins set to 0. - All Padding set to 0. - TextAlign = MiddleLeft. - Button style is Flat. - Setting flat border width to 0 or 1 has no effect on position of text. For pattern illustration: - U = Unknown Pixel (we are not drawing these) - T = Text pixel My drawing: 1. Draw text at x = 0. 2. Draws text 5 pixels from left edge - I can live with that. Pattern: UUUUT Not important: Why is DrawString(...) drawing the text at x=4 instead of x=0? Microsoft drawing: 1. Draws text 11 pixels from left edge. Pattern: UUUUUUUUUUT Important: Where are the extra 6 pixels coming from? I have tried to account for the extra padding by examining the systems information settings. Unfortunately none of those settings explain where the padding is coming from (BorderSize=1, Border3DSize=2). Thanks for any explanation,

      INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

      B Offline
      B Offline
      BillWoodruff
      wrote on last edited by
      #2

      One logical, if unlikely, hypothesis might be that the position of the first character is calculated based on the underlying bounding box of the character which may include a built-in left-margin factor. To exclude this hypothesis, which I'd guess you may have already done, I'd vary the first character from lower to upper case, and compare a "naturally wide" "W" with a "naturally narrow "I." If they are both drawn at identical distances from the left edge of the Button at the Alignment settings you describe: that's one less hypothesis :) A more probable hypothesis (?): the fact you are using the Paint Event and DrawString means you are relying on an internal drawing area that is offset from the absolute pixel edges of the Button: since I never use Paint and DrawString, I don't know how you could test this hypothesis, but I am sure someone else reading this post will. best, Bill

      "It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle

      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