Discussion:
Actual VB question!
(too old to reply)
StrandElectric
2011-06-12 21:11:12 UTC
Permalink
vb6

I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in the text
boxes does not quite line up. I'd like to have them more in the middle
vertically and aligned properly. (I am of course OK for horizontal placeing
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
GS
2011-06-12 22:53:45 UTC
Permalink
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in the text
boxes does not quite line up. I'd like to have them more in the middle
vertically and aligned properly. (I am of course OK for horizontal placeing
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
Font size would be 1 place to look. Control Height would be another.
--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Jason Keats
2011-06-13 02:34:03 UTC
Permalink
Post by GS
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top
(vertically) of the textbox or label. Also captions on the labels and
text in the text boxes does not quite line up. I'd like to have them
more in the middle vertically and aligned properly. (I am of course OK
for horizontal placeing (left right centre)). Is there some control
property I should be tweaking? Apols for such a basic question.
Font size would be 1 place to look. Control Height would be another.
To get finer control of object placement using Ctrl + Arrow keys, you
should look at Tools > Options > General and try modifying the width and
height of the Grid Units or unticking "Align Controls to Grid".
Ivar
2011-06-12 23:58:28 UTC
Permalink
If it's just a few controls then set the TextBox or Label Border and
appearance properties to 0 and place them in a picturebox as you want them
and set the picturebox properties to how you want them to appear
If it's a lot of controls then look in to wrapping the Textbox or label in a
user control.
The label and textbox controls don't expose the methods you are looking for
on their own via VB, don't look to good via API either.
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top
(vertically) of the textbox or label. Also captions on the labels and text
in the text boxes does not quite line up. I'd like to have them more in
the middle vertically and aligned properly. (I am of course OK for
horizontal placeing (left right centre)). Is there some control property I
should be tweaking? Apols for such a basic question.
Dee Earley
2011-06-13 08:19:26 UTC
Permalink
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in the text
boxes does not quite line up. I'd like to have them more in the middle
vertically and aligned properly. (I am of course OK for horizontal placeing
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
Just adjust the Top property to suit your requirements.
Note that the position can vary slightly based on Windows theme, font
sizes, phase of moon, etc :)
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Eric Coleman
2011-06-17 15:04:33 UTC
Permalink
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in the text
boxes does not quite line up. I'd like to have them more in the middle
vertically and aligned properly. (I am of course OK for horizontal placeing
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
Select the controls you want to align, and then from the the "Format"
menu, select "Align" -> "Middles"

There is a lot of neat stuff in the Format menu. Also, you can right
click on the toolbar and add the "Form Editor" toolbar. It can also be
customized to add more of the formatting controls that aren't present.
StrandElectric
2011-06-18 00:23:35 UTC
Permalink
Post by Eric Coleman
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in the text
boxes does not quite line up. I'd like to have them more in the middle
vertically and aligned properly. (I am of course OK for horizontal placeing
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
Select the controls you want to align, and then from the the "Format"
menu, select "Align" -> "Middles"
There is a lot of neat stuff in the Format menu. Also, you can right
click on the toolbar and add the "Form Editor" toolbar. It can also be
customized to add more of the formatting controls that aren't present.
Experimenting now Eric. When I select a control and then go Format > Align >
Middles, as you suggested, I get as far as Align and then all the options
are greyed out. I will continue to try.
John K.Eason
2011-06-18 11:20:00 UTC
Permalink
*Date:* Sat, 18 Jun 2011 10:23:35 +1000
Post by Eric Coleman
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in
the text
Post by Eric Coleman
Post by StrandElectric
boxes does not quite line up. I'd like to have them more in the
middle
Post by Eric Coleman
Post by StrandElectric
vertically and aligned properly. (I am of course OK for
horizontal >> placeing
Post by Eric Coleman
Post by StrandElectric
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
Select the controls you want to align, and then from the the
"Format" menu, select "Align" -> "Middles"
There is a lot of neat stuff in the Format menu. Also, you can
right click on the toolbar and add the "Form Editor" toolbar. It
can also be customized to add more of the formatting controls
that aren't present.
Experimenting now Eric. When I select a control and then go Format
Post by Eric Coleman
Align > Middles, as you suggested, I get as far as Align and then
all the options are greyed out. I will continue to try.
That option is for aligning controls on a form, not for aligning text within a
control (which isn't natively possible for vertical alignment).
To vertically align a label relative to a single-line text box, I've found that
the Top property of the label control needs to be 45 points larger than the textbox
Top property (assuming the desktop is using the default settings, and using
'Classic view in Windows).

Regards
John
StrandElectric
2011-06-18 19:04:49 UTC
Permalink
Post by John K.Eason
*Date:* Sat, 18 Jun 2011 10:23:35 +1000
Post by Eric Coleman
Post by StrandElectric
vb6
I have a problem where the text or caption line up near the top (vertically)
of the textbox or label. Also captions on the labels and text in
the text
Post by Eric Coleman
Post by StrandElectric
boxes does not quite line up. I'd like to have them more in the
middle
Post by Eric Coleman
Post by StrandElectric
vertically and aligned properly. (I am of course OK for
horizontal >> placeing
Post by Eric Coleman
Post by StrandElectric
(left right centre)). Is there some control property I should be tweaking?
Apols for such a basic question.
Select the controls you want to align, and then from the the
"Format" menu, select "Align" -> "Middles"
There is a lot of neat stuff in the Format menu. Also, you can
right click on the toolbar and add the "Form Editor" toolbar. It
can also be customized to add more of the formatting controls
that aren't present.
Experimenting now Eric. When I select a control and then go Format
Post by Eric Coleman
Align > Middles, as you suggested, I get as far as Align and then
all the options are greyed out. I will continue to try.
That option is for aligning controls on a form, not for aligning text within a
control (which isn't natively possible for vertical alignment).
To vertically align a label relative to a single-line text box, I've found that
the Top property of the label control needs to be 45 points larger than the textbox
Top property (assuming the desktop is using the default settings, and using
'Classic view in Windows).
Regards
John
Thanks John. Makes sense. I'll try it!
StrandElectric
2011-06-18 20:29:05 UTC
Permalink
Post by John K.Eason
To vertically align a label relative to a single-line text box, I've found that
the Top property of the label control needs to be 45 points larger than the textbox
Top property (assuming the desktop is using the default settings, and using
'Classic view in Windows).
Regards
John
HI John. Terrific! I have tried that and for the first time my applications
look attractive. Previously I tried moving the controls around in an attempt
to align label text with textbox text, and of course they always sprang to
the grid! You have ended years of frustration. Can I buy you a beer?
John K.Eason
2011-06-18 23:26:00 UTC
Permalink
*Date:* Sun, 19 Jun 2011 06:29:05 +1000
Post by John K.Eason
To vertically align a label relative to a single-line text box,
I've found that the Top property of the label control needs to be 45
points larger than the textbox Top property (assuming the desktop is
using the default settings, and using 'Classic view in Windows).
Regards
John
HI John. Terrific! I have tried that and for the first time my
applications look attractive. Previously I tried moving the
controls around in an attempt to align label text with textbox
text, and of course they always sprang to the grid! You have ended
years of frustration.
You could always turn the grid off and drag them manually, but it rather depends
how steady your hand is when dragging controls around! :^)
As Mike says, it would be safer to do it in code if there's any chance of running
on a non-default system, but all my programs are for my use only, so I don't
bother.
Can I buy you a beer?
That could be tricky as a) you appear to live in Australia and I'm in the UK, and
b) I'm teetotal. I'll accept an e-beer and imagine it's a cup of coffee if you like
though! :^)

Regards
John
ralph
2011-06-19 02:41:52 UTC
Permalink
On Sun, 19 Jun 2011 06:29:05 +1000, "StrandElectric"
Post by StrandElectric
HI John. Terrific! I have tried that and for the first time my applications
look attractive. Previously I tried moving the controls around in an attempt
to align label text with textbox text, and of course they always sprang to
the grid! You have ended years of frustration. Can I buy you a beer?
Memories.

I remember like yesterday the day I was rebuilding data entry forms. I
was carefully deleting controls on one form and positioning and
resizing a new control on another, one by one. A VB veteran looking
over my shoulder said, why don't you select them then copy 'n paste?
Doph!

-ralph
<g>
John K.Eason
2011-06-19 11:22:00 UTC
Permalink
*Date:* Sat, 18 Jun 2011 21:41:52 -0500
On Sun, 19 Jun 2011 06:29:05 +1000, "StrandElectric"
Post by StrandElectric
HI John. Terrific! I have tried that and for the first time my
applications >look attractive. Previously I tried moving the
controls around in an attempt >to align label text with textbox
text, and of course they always sprang to >the grid! You have
ended years of frustration. Can I buy you a beer? >
Memories.
I remember like yesterday the day I was rebuilding data entry
forms. I
was carefully deleting controls on one form and positioning and
resizing a new control on another, one by one. A VB veteran looking
over my shoulder said, why don't you select them then copy 'n paste?
Doph!
-ralph
<g>
Ho yus! Then you found all the indexes of control arrays had been re-ordered...
:^(

Regards
John
ralph
2011-06-19 15:51:06 UTC
Permalink
Post by John K.Eason
*Date:* Sat, 18 Jun 2011 21:41:52 -0500
On Sun, 19 Jun 2011 06:29:05 +1000, "StrandElectric"
Post by StrandElectric
HI John. Terrific! I have tried that and for the first time my
applications >look attractive. Previously I tried moving the
controls around in an attempt >to align label text with textbox
text, and of course they always sprang to >the grid! You have
ended years of frustration. Can I buy you a beer? >
Memories.
I remember like yesterday the day I was rebuilding data entry
forms. I
was carefully deleting controls on one form and positioning and
resizing a new control on another, one by one. A VB veteran looking
over my shoulder said, why don't you select them then copy 'n paste?
Doph!
-ralph
<g>
Ho yus! Then you found all the indexes of control arrays had been re-ordered...
:^(
Thankfully, the same colleague also introduced me to the wonderful
world of Addons.

-ralph
<g>
John K.Eason
2011-06-20 11:07:00 UTC
Permalink
*Date:* Sun, 19 Jun 2011 10:51:06 -0500
Post by John K.Eason
Ho yus! Then you found all the indexes of control arrays had been
re-ordered...
Post by John K.Eason
:^(
Thankfully, the same colleague also introduced me to the wonderful
world of Addons.
-ralph
<g>
Yes. They do come in useful occasionally, especially MZ-Tools!

Regards
John
Deanna Earley
2011-06-20 08:56:30 UTC
Permalink
...the Top property of the label control needs to be 45 points larger...
Minor point, but it's a twip. A point is 20x larger than a twip (and not
evenly divisible by pixels by default)

:p
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
John K.Eason
2011-06-20 11:10:00 UTC
Permalink
*Date:* Mon, 20 Jun 2011 09:56:30 +0100
...the Top property of the label control needs to be 45 points larger...
Minor point, but it's a twip. A point is 20x larger than a twip
(and not evenly divisible by pixels by default)
:p
--
i-Catcher Development Team
http://www.icode.co.uk/icatcher/
Yep. My error.

Regards
John

Mike Williams
2011-06-18 21:55:36 UTC
Permalink
When I select a control and then go Format > Align > Middles I get as far
as Align and then all the options are greyed out.
As John has already said, Format Align is not for aligning text within a
control and you instead need to adjust the Label's Top property with respect
to the TextBox's Top property. However, it is best to do this at runtime
rather than at design time because the required value is not always 45 twips
and it can vary from system to system (often 45 Twips but sometimes 30 or 36
Twips and occasionally some other value) so you are better off doing it in
code. The required offset can be calculated as follows:

Option Explicit
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function GetSystemMetrics _
Lib "user32.dll" (ByVal nIndex As Long) As Long
Private Const EM_GETRECT = &HB2
Private Const SM_CYEDGE = 46
Private LabelOffsetY As Single
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub Form_Load()
Dim r1 As RECT, Y3DBorder As Long
' get pixel thickness of TextBox top 3D border
Y3DBorder = GetSystemMetrics(SM_CYEDGE)
' get pixel offset from top of a TextBox client area to top of Character
cells
SendMessage Text1.hwnd, EM_GETRECT, 0, r1
' calculate total offset in Twips
LabelOffsetY = Me.ScaleY(r1.Top + Y3DBorder, _
vbPixels, Text1.Container.ScaleMode)
End Sub

You can then use the value of LabelOffsetY to adjust the position of each
Label with respect to the position of its associated TextBox, for example:

Label1.Top = Text1.Top + LabelOffsetY

Mike
Loading...