PC Review


Reply
Thread Tools Rate Thread

Center Userform Controls

 
 
=?Utf-8?B?U2hhd24=?=
Guest
Posts: n/a
 
      20th Jun 2007
I am using the following code to make the userform fill the entire screen:

Private mlAppWindowState As Long
Private Sub UserForm_Initialize()
With Application
mlAppWindowState = .WindowState
.WindowState = xlMaximized
Me.Move .Left, .Top, .Width, .Height
End With
End Sub
Private Sub UserForm_Terminate()
Application.WindowState = mlAppWindowState
End Sub


What I need is VBA to center the userform controls. Maybe I could put the
controls inside a frame and I just need to the frame to center. I am not
sure. But I need VBA to position the controls. Can someone get me started?


--
Thanks
Shawn
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      20th Jun 2007
Just do something like

With Me
.cmdOK.Left = .Width \ 2 - .cmdOK.Width \ 2
.cmdQuit.Left = .Width \ 2 - .cmdQuit.Width \ 2
End With


in the form activate event

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Shawn" <(E-Mail Removed)> wrote in message
news:3D0C6471-198E-4FD4-9C6D-(E-Mail Removed)...
>I am using the following code to make the userform fill the entire screen:
>
> Private mlAppWindowState As Long
> Private Sub UserForm_Initialize()
> With Application
> mlAppWindowState = .WindowState
> .WindowState = xlMaximized
> Me.Move .Left, .Top, .Width, .Height
> End With
> End Sub
> Private Sub UserForm_Terminate()
> Application.WindowState = mlAppWindowState
> End Sub
>
>
> What I need is VBA to center the userform controls. Maybe I could put the
> controls inside a frame and I just need to the frame to center. I am not
> sure. But I need VBA to position the controls. Can someone get me
> started?
>
>
> --
> Thanks
> Shawn



 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      20th Jun 2007
the controls have top, left, width and height properties as well, Just
calculate where you want them and then set those attributes.

To get the middle of the form, divide the width in half and add it the left
position. Subtract half the width of the control to get the left position
for the control. Use logic related to that to calculate where you want you
controls.

--
Regards,
Tom Ogilvy


"Shawn" wrote:

> I am using the following code to make the userform fill the entire screen:
>
> Private mlAppWindowState As Long
> Private Sub UserForm_Initialize()
> With Application
> mlAppWindowState = .WindowState
> .WindowState = xlMaximized
> Me.Move .Left, .Top, .Width, .Height
> End With
> End Sub
> Private Sub UserForm_Terminate()
> Application.WindowState = mlAppWindowState
> End Sub
>
>
> What I need is VBA to center the userform controls. Maybe I could put the
> controls inside a frame and I just need to the frame to center. I am not
> sure. But I need VBA to position the controls. Can someone get me started?
>
>
> --
> Thanks
> Shawn

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      20th Jun 2007
Shawn,
There are various resizer classes out there, most designed for VB5/6 forms
rather than VBA userforms, but you could edit to suit. e.g.
http://www.dutchthewiz.com/vb/api/

NickHK

"Shawn" <(E-Mail Removed)> ¼¶¼g©ó¶l¥ó·s»D:3D0C6471-198E-4FD4-9C6D-(E-Mail Removed)...
>I am using the following code to make the userform fill the entire screen:
>
> Private mlAppWindowState As Long
> Private Sub UserForm_Initialize()
> With Application
> mlAppWindowState = .WindowState
> .WindowState = xlMaximized
> Me.Move .Left, .Top, .Width, .Height
> End With
> End Sub
> Private Sub UserForm_Terminate()
> Application.WindowState = mlAppWindowState
> End Sub
>
>
> What I need is VBA to center the userform controls. Maybe I could put the
> controls inside a frame and I just need to the frame to center. I am not
> sure. But I need VBA to position the controls. Can someone get me
> started?
>
>
> --
> Thanks
> Shawn



 
Reply With Quote
 
=?Utf-8?B?U2hhd24=?=
Guest
Posts: n/a
 
      20th Jun 2007
I used this code, for example, and it worked great.

usfWorkOrder.Label1.Left = (usfWorkOrder.Width) / 2


--
Thanks
Shawn


"Tom Ogilvy" wrote:

> the controls have top, left, width and height properties as well, Just
> calculate where you want them and then set those attributes.
>
> To get the middle of the form, divide the width in half and add it the left
> position. Subtract half the width of the control to get the left position
> for the control. Use logic related to that to calculate where you want you
> controls.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Shawn" wrote:
>
> > I am using the following code to make the userform fill the entire screen:
> >
> > Private mlAppWindowState As Long
> > Private Sub UserForm_Initialize()
> > With Application
> > mlAppWindowState = .WindowState
> > .WindowState = xlMaximized
> > Me.Move .Left, .Top, .Width, .Height
> > End With
> > End Sub
> > Private Sub UserForm_Terminate()
> > Application.WindowState = mlAppWindowState
> > End Sub
> >
> >
> > What I need is VBA to center the userform controls. Maybe I could put the
> > controls inside a frame and I just need to the frame to center. I am not
> > sure. But I need VBA to position the controls. Can someone get me started?
> >
> >
> > --
> > Thanks
> > Shawn

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tom Ogilvy -- Center Userform Below Calling Toobar Icon Zone Microsoft Excel Programming 2 28th Mar 2007 02:50 AM
userform to appear in the center of the screen =?Utf-8?B?ZXJuaWU=?= Microsoft Excel Programming 3 28th Dec 2006 05:50 AM
mutlipage in the center of userform Pierre via OfficeKB.com Microsoft Excel Programming 1 4th Nov 2005 08:49 AM
UserForm position other than center of the screen. Jay Fincannon Microsoft Excel Programming 1 23rd Jan 2005 02:23 AM
textbox in userform(vertical center) tom taol Microsoft Excel Programming 0 22nd Jan 2005 08:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:12 PM.