Is there a way to somehow adjust with code the height and width
properties of a userform to make it "snap" all over the user's screen,
all over -- any -- user's screen, so that the form looks like a "real"
program's user interface?
Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
--
Ctrl-Alt-Dlt-Hlp ô)ô
Private Sub UserForm_Activate()
With Application
Me.Top = .Top
Me.Left = .Left
Me.Height = .Height
Me.Width = .Width
End With
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
<m_r_be...@my-deja.com> wrote in message
news:8ri3r8$50i$1...@nnrp1.deja.com...
--
Ctrl-Alt-Dlt-Hlp ô)ô
In a class, properties and methods "roll up" to Me. Therefore, you don't
even need to use the "Me" qualifier. You could write the code as
With Application
Top = .Top
Left = .Left
Height = .Height
Width = .Width
End With
I think this is sloppy coding, but it will work. In classes, unqualifed
object references go up through "Me" rather than through "Application" (if
there is a property of "Me" with the proper name). This can cause code to
run differently when used in a class rather than a standard code module.
For example, ActiveSheet, when used in a standard code module, refers to the
sheet which is active in the application (Application.ActiveSheet). However,
in the ThisWorkbook class, it refers to the sheet which is active *in the
workbook*, which may not be the sheet which is active in the application. In
other words, Application.ActiveSheet is not necessariliy the same as
ThisWorkbook.ActiveSheet, and an unqualified "ActiveSheet" may behave
differently in ThisWorkbook and a standard code module.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"Ctrl-Alt-Dlt-Hlp" <wils...@my-deja.com> wrote in message
news:8ri83h$91j$1...@nnrp1.deja.com...
One other way would be to create a custom WindowState proerty for your
userform.
Something like:
------------------------------------------------------------
Option Explicit
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" _
( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) _
As Long
Private Declare Function ShowWindow _
Lib "user32" _
( _
ByVal hwnd As Long, _
ByVal nCmdShow As Long _
) _
As Long
Private Declare Function IsZoomed _
Lib "user32" _
( _
ByVal hwnd As Long _
) _
As Long
Private Declare Function IsIconic _
Lib "user32" _
( _
ByVal hwnd As Long _
) _
As Long
Property Get hwnd() As Long
'custom hWnd property for the Userform class
hwnd = FindWindow _
( _
lpClassName:=IIf(Val(Application.Version) > 8, _
"ThunderDFrame", _
"ThunderXFrame"), _
lpWindowName:=Me.Caption _
)
End Property
Property Let WindowState(State As String)
'custom WindowsState 'let' property for the userform class
'this property requires the "hwnd" custom property
Const SW_SHOWMAXIMIZED = 3
Const SW_NORMAL = 1
Const SW_MINIMIZE = 6
If LCase(State) = "maximized" Then
If CBool(IsZoomed(hwnd:=Me.hwnd)) = False Then
Call ShowWindow(hwnd:=Me.hwnd, nCmdShow:=SW_SHOWMAXIMIZED)
End If
ElseIf LCase(State) = "minimized" Then
If CBool(IsIconic(hwnd:=Me.hwnd)) = False Then
Call ShowWindow(hwnd:=Me.hwnd, nCmdShow:=SW_MINIMIZE)
End If
Else
Call ShowWindow(hwnd:=Me.hwnd, nCmdShow:=SW_NORMAL)
End If
End Property
Property Get WindowState() As String
'custom WindowsState 'get' property for the userform class
'only 'maximised' and 'normal' states are available here
If CBool(IsZoomed(hwnd:=Me.hwnd)) = True Then
WindowState = "Maximized"
ElseIf CBool(IsIconic(hwnd:=Me.hwnd)) = True Then
WindowState = "Minimized"
Else
WindowState = "Normal"
End If
End Property
------------------------------------------------------------------
which you can simply se like any other userform property, e.g:
---------------------------------
Private Sub UserForm_Click()
Me.WindowState = "Maximized"
End Sub
---------------------------------
in such an example hen you click on the userform, it gets maximized.
Similarly you could put it in the Activate event to maximize it on
showing it.
You can use the Resize event to see when it is maximised , e.g.:
---------------------------------------
Private Sub UserForm_Resize()
If Me.WindowState = "Maximized" Then MsgBox "I'm maximized"
End Sub
---------------------------------------
In this way you can know when to read the Width and Height of the
useform and resize the child controls accordingly.
HTH
Stratos