Click to See Complete Forum and Search --> : Lining up the text in a label with text in a text box


Illyana Rasputin
11-18-2003, 01:20 PM
Hello all,

I am having trouble lining up the text in a label with text in a text box
located to the right of it.

The regular form tools in Visual Studio .NET seem to be based on the outside
of the label and text box controls (sort of a poor design since most layout
tools for text based objects use the baseline of the text which makes more
since).

Is there an easy way to line the text up automatically? If I allow the user
to set their own preferences for the text size, then I need to adjust the
layout.

The issue mainly seems to be that the baseline of the text in the labels
is about dead center of the label, whereas the text in the text boxes is
done properly (the center of the text is close to the center of the text
box.

Best regards,
Illyana Rasputin
illyana888@hotmail.com

PWilmarth
11-18-2003, 01:20 PM
If you want to vary the size of the the Label and Textbox, based on some user
preferences, then you need to use the DrawString method of GDI+. You can
then set the ResizeRedraw property to true for each control so that it automatically
resizes when the text size changes.

As far as alignment, you can use the mouse and select the controls you want
to align as a group. Then, under Format in the Menu, select Align and align
the controls as a group Left, Right, Tops, etc.

Illyana Rasputin
11-18-2003, 01:20 PM
Hello,

Thanks for the reply, but you missed the issue. The alignment functions
align the controls based on the outside limits as opposed to the text 'INSIDE'
the controls.

My guess is that the 'label' control and the 'text box' control were designed
by two different teams. The one that did the 'text box' control being the
better of the two and formated the box using the standard of it being in
the center of the box, whereas the 'label' control, the text is not centered
in the box at all (up/down). The bottom of the characters is close to the
middle of the box (as opposed to being centered such as is the text box).

This is purely a cosmetic gripe of mine. Lining up the controls is simple.
I want to line up the text in two different types of controls and be able
to do it dynamically.

I will do my best to make it visual.
__________________ __________________
| | | |
| Text in a label | | |
| | |Text in a text box|
| | | |
|__________________| |__________________|

The text in the label is not situated in the center (vertically). It floats
up a bit from it. If the text was in the center such as is the case with
the text in the text box control, then at least if the text were the same
size, I could be assured of it lining up properly.

Ideally, there would be a 'baseline alignment' feature that would allow you
to select two or more controls and have them lined up NOT by the outside
of the control, but by the baseline (bottom) of the text within the control.

I was wondering if anyone knows of such a feature. If there is one like
that in Visual Studio haven't seen been able to find it so far, but I am
still hopeful.

So far, Visual Studio has had lots of hard to find features (with little
or no documentation) that are very powerful/useful.

(still hoping)
Illyana Rasputin

"PWilmarth" <vb.@127.0.0.1> wrote:
>
>If you want to vary the size of the the Label and Textbox, based on some
user
>preferences, then you need to use the DrawString method of GDI+. You can
>then set the ResizeRedraw property to true for each control so that it automatically
>resizes when the text size changes.
>
>As far as alignment, you can use the mouse and select the controls you want
>to align as a group. Then, under Format in the Menu, select Align and align
>the controls as a group Left, Right, Tops, etc.

PWilmarth
11-18-2003, 01:20 PM
I guess my question to you is have you tried GDI+?

It does seem like a simple matter, and should be relatively easy to fix without
having to use it, but you can do a lot precision work with GDI+, and get
the text to line up exactly the way you want.

Russell Jones
11-18-2003, 01:20 PM
Just a note. While it won't help you in this version, the next (Whidbey)
release of Visual Studio (currently in limited-release beta) solves this
problem in the designer, by providing smart alignment lines that let you
align controls on text baselines as well as on control edges.

"PWilmarth" <vb.@127.0.0.1> wrote in message
news:3fb20f00$1@devx7.web.devx.com...
>
> I guess my question to you is have you tried GDI+?
>
> It does seem like a simple matter, and should be relatively easy to fix
without
> having to use it, but you can do a lot precision work with GDI+, and get
> the text to line up exactly the way you want.

Tim Ellison
11-18-2003, 01:20 PM
> My guess is that the 'label' control and the 'text box' control were
designed
> by two different teams.

One renders a <SPAN> and the other an <INPUT>. The same problem persists in
traditional HTML as well.

One suggestion I would make it to use an HTMLTableCell rather than a label.
You can then set the innerText or innerHTML appropriately. The alignment
then, falls back to the individual cells align and valign attributes (which
you could simplify by using a stylesheet class).

My two sense.
--
Regards,

Tim Ellison
"Illyana Rasputin" <illyana888@hotmail.com> wrote in message
news:3fb19692@devx7.web.devx.com...
>
> Hello,
>
> Thanks for the reply, but you missed the issue. The alignment functions
> align the controls based on the outside limits as opposed to the text
'INSIDE'
> the controls.
>
> My guess is that the 'label' control and the 'text box' control were
designed
> by two different teams. The one that did the 'text box' control being the
> better of the two and formated the box using the standard of it being in
> the center of the box, whereas the 'label' control, the text is not
centered
> in the box at all (up/down). The bottom of the characters is close to the
> middle of the box (as opposed to being centered such as is the text box).
>
> This is purely a cosmetic gripe of mine. Lining up the controls is
simple.
> I want to line up the text in two different types of controls and be able
> to do it dynamically.
>
> I will do my best to make it visual.
> __________________ __________________
> | | | |
> | Text in a label | | |
> | | |Text in a text box|
> | | | |
> |__________________| |__________________|
>
> The text in the label is not situated in the center (vertically). It
floats
> up a bit from it. If the text was in the center such as is the case with
> the text in the text box control, then at least if the text were the same
> size, I could be assured of it lining up properly.
>
> Ideally, there would be a 'baseline alignment' feature that would allow
you
> to select two or more controls and have them lined up NOT by the outside
> of the control, but by the baseline (bottom) of the text within the
control.
>
> I was wondering if anyone knows of such a feature. If there is one like
> that in Visual Studio haven't seen been able to find it so far, but I am
> still hopeful.
>
> So far, Visual Studio has had lots of hard to find features (with little
> or no documentation) that are very powerful/useful.
>
> (still hoping)
> Illyana Rasputin
>
> "PWilmarth" <vb.@127.0.0.1> wrote:
> >
> >If you want to vary the size of the the Label and Textbox, based on some
> user
> >preferences, then you need to use the DrawString method of GDI+. You can
> >then set the ResizeRedraw property to true for each control so that it
automatically
> >resizes when the text size changes.
> >
> >As far as alignment, you can use the mouse and select the controls you
want
> >to align as a group. Then, under Format in the Menu, select Align and
align
> >the controls as a group Left, Right, Tops, etc.
>

Illyana Rasputin
11-18-2003, 01:20 PM
Thanks all for the ideas. I am not sure which way I am going to go as of
yet.

I came accross the issue prior to the cosemetics phase(after all logical
and functional issues have been resolved) of the project. It will probably
be 2-3 weeks before I have to iron out the cosmetic issues.

From what I have read on Longhorn and Whidbey, things will indeed be interesting
in the next generation of Windows software programming.

I didn't know that this was one of the many issues that Whidbey addresses,
but from what little I have seen, the interface is even easier to use. I
can't wait to shell out the $1200+ (I will probably go the MSDN route).

Thanks again,
Illyana Rasputin


"Tim Ellison" <timmysubs@earthlink.net> wrote:
>> My guess is that the 'label' control and the 'text box' control were
>designed
>> by two different teams.
>
>One renders a <SPAN> and the other an <INPUT>. The same problem persists
in
>traditional HTML as well.
>
>One suggestion I would make it to use an HTMLTableCell rather than a label.
>You can then set the innerText or innerHTML appropriately. The alignment
>then, falls back to the individual cells align and valign attributes (which
>you could simplify by using a stylesheet class).
>
>My two sense.
>--
>Regards,
>
>Tim Ellison
>"Illyana Rasputin" <illyana888@hotmail.com> wrote in message
>news:3fb19692@devx7.web.devx.com...
>>
>> Hello,
>>
>> Thanks for the reply, but you missed the issue. The alignment functions
>> align the controls based on the outside limits as opposed to the text
>'INSIDE'
>> the controls.
>>
>> My guess is that the 'label' control and the 'text box' control were
>designed
>> by two different teams. The one that did the 'text box' control being
the
>> better of the two and formated the box using the standard of it being
in
>> the center of the box, whereas the 'label' control, the text is not
>centered
>> in the box at all (up/down). The bottom of the characters is close to
the
>> middle of the box (as opposed to being centered such as is the text box).
>>
>> This is purely a cosmetic gripe of mine. Lining up the controls is
>simple.
>> I want to line up the text in two different types of controls and be
able
>> to do it dynamically.
>>
>> I will do my best to make it visual.
>> __________________ __________________
>> | | | |
>> | Text in a label | | |
>> | | |Text in a text box|
>> | | | |
>> |__________________| |__________________|
>>
>> The text in the label is not situated in the center (vertically). It
>floats
>> up a bit from it. If the text was in the center such as is the case with
>> the text in the text box control, then at least if the text were the same
>> size, I could be assured of it lining up properly.
>>
>> Ideally, there would be a 'baseline alignment' feature that would allow
>you
>> to select two or more controls and have them lined up NOT by the outside
>> of the control, but by the baseline (bottom) of the text within the
>control.
>>
>> I was wondering if anyone knows of such a feature. If there is one like
>> that in Visual Studio haven't seen been able to find it so far, but I
am
>> still hopeful.
>>
>> So far, Visual Studio has had lots of hard to find features (with little
>> or no documentation) that are very powerful/useful.
>>
>> (still hoping)
>> Illyana Rasputin
>>
>> "PWilmarth" <vb.@127.0.0.1> wrote:
>> >
>> >If you want to vary the size of the the Label and Textbox, based on some
>> user
>> >preferences, then you need to use the DrawString method of GDI+. You
can
>> >then set the ResizeRedraw property to true for each control so that it
>automatically
>> >resizes when the text size changes.
>> >
>> >As far as alignment, you can use the mouse and select the controls you
>want
>> >to align as a group. Then, under Format in the Menu, select Align and
>align
>> >the controls as a group Left, Right, Tops, etc.
>>
>
>

Vlad
11-18-2003, 01:20 PM
Hi Illyana,

As a quick fix use text box control instead of label control. Adjust all
it's parameters that it looks like label box. At least lock it.

Actually there is no need for label control. Label control is just a subset
of text box control.

Hope it helps.

Regards,
Vlad.




"Illyana Rasputin" <illyana888@hotmail.com> wrote:
>
>Thanks all for the ideas. I am not sure which way I am going to go as of
>yet.
>
>I came accross the issue prior to the cosemetics phase(after all logical
>and functional issues have been resolved) of the project. It will probably
>be 2-3 weeks before I have to iron out the cosmetic issues.
>
>From what I have read on Longhorn and Whidbey, things will indeed be interesting
>in the next generation of Windows software programming.
>
>I didn't know that this was one of the many issues that Whidbey addresses,
>but from what little I have seen, the interface is even easier to use.
I
>can't wait to shell out the $1200+ (I will probably go the MSDN route).
>
>Thanks again,
>Illyana Rasputin
>
>
>"Tim Ellison" <timmysubs@earthlink.net> wrote:
>>> My guess is that the 'label' control and the 'text box' control were
>>designed
>>> by two different teams.
>>
>>One renders a <SPAN> and the other an <INPUT>. The same problem persists
>in
>>traditional HTML as well.
>>
>>One suggestion I would make it to use an HTMLTableCell rather than a label.
>>You can then set the innerText or innerHTML appropriately. The alignment
>>then, falls back to the individual cells align and valign attributes (which
>>you could simplify by using a stylesheet class).
>>
>>My two sense.
>>--
>>Regards,
>>
>>Tim Ellison
>>"Illyana Rasputin" <illyana888@hotmail.com> wrote in message
>>news:3fb19692@devx7.web.devx.com...
>>>
>>> Hello,
>>>
>>> Thanks for the reply, but you missed the issue. The alignment functions
>>> align the controls based on the outside limits as opposed to the text
>>'INSIDE'
>>> the controls.
>>>
>>> My guess is that the 'label' control and the 'text box' control were
>>designed
>>> by two different teams. The one that did the 'text box' control being
>the
>>> better of the two and formated the box using the standard of it being
>in
>>> the center of the box, whereas the 'label' control, the text is not
>>centered
>>> in the box at all (up/down). The bottom of the characters is close to
>the
>>> middle of the box (as opposed to being centered such as is the text box).
>>>
>>> This is purely a cosmetic gripe of mine. Lining up the controls is
>>simple.
>>> I want to line up the text in two different types of controls and be
>able
>>> to do it dynamically.
>>>
>>> I will do my best to make it visual.
>>> __________________ __________________
>>> | | | |
>>> | Text in a label | | |
>>> | | |Text in a text box|
>>> | | | |
>>> |__________________| |__________________|
>>>
>>> The text in the label is not situated in the center (vertically). It
>>floats
>>> up a bit from it. If the text was in the center such as is the case
with
>>> the text in the text box control, then at least if the text were the
same
>>> size, I could be assured of it lining up properly.
>>>
>>> Ideally, there would be a 'baseline alignment' feature that would allow
>>you
>>> to select two or more controls and have them lined up NOT by the outside
>>> of the control, but by the baseline (bottom) of the text within the
>>control.
>>>
>>> I was wondering if anyone knows of such a feature. If there is one like
>>> that in Visual Studio haven't seen been able to find it so far, but I
>am
>>> still hopeful.
>>>
>>> So far, Visual Studio has had lots of hard to find features (with little
>>> or no documentation) that are very powerful/useful.
>>>
>>> (still hoping)
>>> Illyana Rasputin
>>>
>>> "PWilmarth" <vb.@127.0.0.1> wrote:
>>> >
>>> >If you want to vary the size of the the Label and Textbox, based on
some
>>> user
>>> >preferences, then you need to use the DrawString method of GDI+. You
>can
>>> >then set the ResizeRedraw property to true for each control so that
it
>>automatically
>>> >resizes when the text size changes.
>>> >
>>> >As far as alignment, you can use the mouse and select the controls you
>>want
>>> >to align as a group. Then, under Format in the Menu, select Align and
>>align
>>> >the controls as a group Left, Right, Tops, etc.
>>>
>>
>>
>