ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stretching a userform with the mouse (https://www.excelbanter.com/excel-programming/348588-stretching-userform-mouse.html)

Pierre Archambault

Stretching a userform with the mouse
 
Hi,

I have a workbook that uses a userform to display some help text. (.pdf)

I use the "WebBrowser" control to do so. I set a default size of 640 x 480
for the userform. However I would like the user be able to modify the window
size the way we usually do: stretching it by the lower right corner.

If someone could help me with that challenge, I would appreciate.

Thanks

Pierre





Leith Ross[_401_]

Stretching a userform with the mouse
 

Hello Pierre,

Add a new VBA module to your project and copy the following code into
it.

CALLING THE FORM RESIZE CODE:
In the UserForm Activate event add the following line...

Call MakeFormResizable


Code:
--------------------

'API calls and constants
'
'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "User32.dll" () As Long

Private Declare Function GetWindowLong _
Lib "User32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong _
Lib "User32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable frame

Public Sub MakeFormResizable()

Dim lStyle As Long
Dim hWnd As Long
Dim RetVal

hWnd = GetActiveWindow

'Get the basic window style
lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME

'Set the basic window styles
RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495084


Pierre Archambault

Stretching a userform with the mouse
 
Thank you very much

Pierre

"Leith Ross" a
écrit dans le message de
...

Hello Pierre,

Add a new VBA module to your project and copy the following code into
it.

CALLING THE FORM RESIZE CODE:
In the UserForm Activate event add the following line...

Call MakeFormResizable


Code:
--------------------

'API calls and constants
'
'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "User32.dll" () As Long

Private Declare Function GetWindowLong _
Lib "User32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong _
Lib "User32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE As Long = (-16) 'The offset of a

window's style
Private Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable

frame

Public Sub MakeFormResizable()

Dim lStyle As Long
Dim hWnd As Long
Dim RetVal

hWnd = GetActiveWindow

'Get the basic window style
lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME

'Set the basic window styles
RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:

http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495084





All times are GMT +1. The time now is 05:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com