Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.visual.misc > #275
| From | "Mike Williams" <Mike@WhiskyAndCoke.com> |
|---|---|
| Newsgroups | comp.lang.basic.visual.misc |
| Subject | Re: Actual VB question! |
| Date | 2011-06-18 22:55 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <itj6se$si5$1@dont-email.me> (permalink) |
| References | <4df52b72$1@dnews.tpgi.com.au> <itfqe1$e3a$1@speranza.aioe.org> <4dfbf00c@dnews.tpgi.com.au> |
"StrandElectric" <Strand@dummyspit> wrote in message
news:4dfbf00c@dnews.tpgi.com.au...
> 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
Back to comp.lang.basic.visual.misc | Previous | Next — Previous in thread | Find similar
Actual VB question! "StrandElectric" <Strand@dummyspit> - 2011-06-13 07:11 +1000
Re: Actual VB question! GS <gs@somewhere.net> - 2011-06-12 18:53 -0400
Re: Actual VB question! Jason Keats <jkeats@melbpcDeleteThis.org.au> - 2011-06-13 12:34 +1000
Re: Actual VB question! "Ivar" <ivar.ekstromer000@ntlworld.com> - 2011-06-13 00:58 +0100
Re: Actual VB question! Dee Earley <dee.earley@icode.co.uk> - 2011-06-13 09:19 +0100
Re: Actual VB question! Eric Coleman <eric@strategon.com> - 2011-06-17 10:04 -0500
Re: Actual VB question! "StrandElectric" <Strand@dummyspit> - 2011-06-18 10:23 +1000
Re: Actual VB question! john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2011-06-18 12:20 +0100
Re: Actual VB question! "StrandElectric" <Strand@dummyspit> - 2011-06-19 05:04 +1000
Re: Actual VB question! "StrandElectric" <Strand@dummyspit> - 2011-06-19 06:29 +1000
Re: Actual VB question! john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2011-06-19 00:26 +0100
Re: Actual VB question! ralph <nt_consulting64@yahoo.net> - 2011-06-18 21:41 -0500
Re: Actual VB question! john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2011-06-19 12:22 +0100
Re: Actual VB question! ralph <nt_consulting64@yahoo.net> - 2011-06-19 10:51 -0500
Re: Actual VB question! john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2011-06-20 12:07 +0100
Re: Actual VB question! Deanna Earley <dee.earley@icode.co.uk> - 2011-06-20 09:56 +0100
Re: Actual VB question! john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2011-06-20 12:10 +0100
Re: Actual VB question! "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-06-18 22:55 +0100
csiph-web