Control spacing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John B

    #1

    Control spacing

    Does anyone know how to determine the exact coordinates of the text
    within a label/checkbox/whatever?

    I know I could use MeasureCharacte rRanges but I think there's an easier way.
    The vs designer allows snapping to the edge of the text (not the edge of
    the label) and I'd like to be able to replicate that easily in code.

    TIA

    JB
  • Peter Duniho

    #2
    Re: Control spacing

    On Wed, 13 Aug 2008 18:14:15 -0700, John B <jbngspam@yahoo .comwrote:
    Does anyone know how to determine the exact coordinates of the text
    within a label/checkbox/whatever?
    >
    I know I could use MeasureCharacte rRanges but I think there's an easier
    way.
    What could be easier than getting an exact measurement of where the text
    is and calculating its position based on that?

    Actually, I should point out that for text display in Forms, you really
    want TextRenderer.Me asureText(), because if I recall correctly
    TextRenderer is what the Forms controls use to display text. Getting
    exactly correct measurements can be tricky, because there's a lot of
    formatting options. :) But assuming you get it right, it should give you
    exactly the information you want (assuming you really want "the exact
    coordinates of the text within a label/checkbox/whatever").

    Pete

    Comment

    • John B

      #3
      Re: Control spacing

      Peter Duniho wrote:
      On Wed, 13 Aug 2008 18:14:15 -0700, John B <jbngspam@yahoo .comwrote:
      >
      >Does anyone know how to determine the exact coordinates of the text
      >within a label/checkbox/whatever?
      >>
      >I know I could use MeasureCharacte rRanges but I think there's an
      >easier way.
      >
      What could be easier than getting an exact measurement of where the text
      is and calculating its position based on that?
      >
      Sure, but i'd prefer to use an existing mechanism (if it exists).

      Such as Control.Padding , but it is zero for all the controls i've
      checked so it doesnt apply.
      I'd think that the label/whatever would calculate this info once and
      then cache that value until it becomes stale and then recalc and so on.
      Actually, I should point out that for text display in Forms, you really
      want TextRenderer.Me asureText(),
      <...>

      Yep, rings a bell, thanks.

      Cheers,

      JB

      Comment

      Working...