MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 2nd, 2002, 05:46 AM   #1
Steve Jukes
Board Regular
 
Join Date: Apr 2002
Posts: 83
Default

Can anyone tell me how to make a userform maximize to the screen size regardless of the screen settings.

Please help!!
Steve Jukes is offline   Reply With Quote
Old May 2nd, 2002, 05:59 AM   #2
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-02 04:46, Steve Jukes wrote:
Can anyone tell me how to make a userform maximize to the screen size regardless of the screen settings.

Please help!!
Perhaps this will help
This option places the Min/Max buttons on the
Userform.....if you want it to Max all the time then look @ Option2


Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

Private Const GWL_STYLE As Long = (-16) 'Sets a new window style
Private Const WS_SYSMENU As Long = &H80000 'Windows style
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const SW_SHOWMAXIMIZED = 3

Private Sub UserForm_Activate()
Dim lFormHandle As Long, lStyle As Long
'===========================================
'= Originally from Dax =
'= Modified with comments by Ivan F Moala =
'= 22/07/01 =
'===========================================

'Lets find the UserForm Handle the function below retrieves the handle
'to the top-level window whose class name ("ThunderDFrame" for Excel)
'and window name (me.caption or UserformName caption) match the specified strings.
lFormHandle = FindWindow("ThunderDFrame", Me.Caption)

'The GetWindowLong function retrieves information about the specified window.
'The function also retrieves the 32-bit (long) value at the specified offset
'into the extra window memory of a window.
lStyle = GetWindowLong(lFormHandle, GWL_STYLE)

'lStyle is the New window style so lets set it up with the following
lStyle = lStyle Or WS_SYSMENU 'SystemMenu
lStyle = lStyle Or WS_MINIMIZEBOX 'With MinimizeBox
lStyle = lStyle Or WS_MAXIMIZEBOX 'and MaximizeBox

'Now lets set up our New window the SetWindowLong function changes
'the attributes of the specified window , given as lFormHandle,
'GWL_STYLE = New windows style, and our Newly defined style = lStyle
SetWindowLong lFormHandle, GWL_STYLE, (lStyle)

'Remove >'< if you want to show form Maximised
'ShowWindow lFormHandle, SW_SHOWMAXIMIZED 'Shows Form Maximized

'The DrawMenuBar function redraws the menu bar of the specified window.
'We need this as we have changed the menu bar after Windows has created it.
'All we need is the Handle.
DrawMenuBar lFormHandle

End Sub


OPTION2


Option Explicit

Private Const SM_CYSCREEN As Long = 1
Private Const SM_CXSCREEN As Long = 0
Const SM_CXFULLSCREEN = 16
Const SM_CYFULLSCREEN = 17
Const SM_CXMINTRACK = 34
Const SM_CYMINTRACK = 35
Const SM_CXMAXIMIZED = 61
Const SM_CYMAXIMIZED = 62
Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long


Private Sub UserForm_Activate()
Dim lScreenHeight As Long, lScreenWidth As Long
Dim lwinwidth, lWinHeight
lScreenHeight = GetSystemMetrics(SM_CYMAXIMIZED) '(SM_CYSCREEN)
lScreenWidth = GetSystemMetrics(SM_CXMAXIMIZED) '(SM_CXSCREEN)
'lwinwidth = ActiveWindow.PointsToScreenPixelsX(lScreenWidth)
'lWinHeight = ActiveWindow.PointsToScreenPixelsY(lScreenHeight)

Me.Left = 0
Me.Top = 0
Me.Height = lScreenHeight ' - 200
Me.Width = lScreenWidth 'lwinwidth 'lScreenWidth
End Sub






__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 2nd, 2002, 07:05 AM   #3
Steve Jukes
Board Regular
 
Join Date: Apr 2002
Posts: 83
Default

Ivan thank you the 1st option works fine if you remove the (') symbol were you say so, so the form maximses on being activated.
I found the 2nd option opened the form to big and therefore i needed to divide the scrrenwidth by 1.35 setting and screenheight setting by by 1.40 for it to reduce to screen size.

Other than that it worked fine.
Steve Jukes is offline   Reply With Quote
Old Oct 2nd, 2002, 10:23 PM   #4
RogerC
Board Regular
 
Join Date: Mar 2002
Location: Phoenix, Arizona
Posts: 454
Default

Ivan - Option 2 worked for me. Thanks! Is there a way to make the controls on the form re-position based on the users screen size?
RogerC is offline   Reply With Quote
Old Oct 3rd, 2002, 12:53 AM   #5
Ekim
Board Regular
 
Join Date: Jun 2002
Location: Perth, Australia
Posts: 1,416
Default

Try this in the Form module:


Private Sub UserForm_Initialize()
With Application
Me.Top = .Top
Me.Left = .Left
Me.Height = .Height
Me.Width = .Width
End With
End Sub


The code leaves the taskbar and menubar displayed (on my PC).

Regards,

Mike

Ekim is offline   Reply With Quote
Old Oct 3rd, 2002, 03:59 PM   #6
RogerC
Board Regular
 
Join Date: Mar 2002
Location: Phoenix, Arizona
Posts: 454
Default

Ekim - Are you saying that code will re-position the controls on a UserForm based on the size of the users screen? It didn't work for me. ?
RogerC is offline   Reply With Quote
Old Oct 4th, 2002, 04:14 AM   #7
Steve Jukes
Board Regular
 
Join Date: Apr 2002
Posts: 83
Default

Roger C
I was altered to your posts as when I set the original question I asked the board to notify me of any replies.
I have now, using Ivan cde set a form up with various controls and made it resize depending on the users screen setting it will also resize and reposition all controls depending on the new sise of the userform.
I hope this code helps, I must admit that I took some from other posts so this is not all my work!!!

This code is placed in the userform initialise section.
TextBox1 = Me.Width
TextBox2 = Me.Height

This code is placed in the userform activate section.

Dim ctl As Object
Dim i As Integer
FW = Val(Userform1.TextBox1)'This takes the width of the user before it maximises
FH = Val(userform1.TextBox2)''This takes the hieght of the user before it maximises
nfw = userform1.Width' This is the userforms new width
nfh = userform1.Height' This the userforms new height

On Error Resume Next
For Each ctl In userform1.Controls
If ctl.Left > 0 Then ctl.Left = (((ctl.Left)) * (nfw / FW))
If ctl.Top > 0 Then ctl.Top = (ctl.Top * (nfh / FH))

ctl.Width = (ctl.Width * (nfw / FW))


'ctl.Width = (ctl.Width * (nfw / FW))
ctl.Height = (ctl.Height * (nfh / FW))

ctl.Font.Name = "Arial"

If TypeName(ctl) = "ListBox" Then

ctl.Font.Size = ctl.Font.Size * ((nfh / FH)) - 2
Else

ctl.Font.Size = ctl.Font.Size * ((nfh / FH))
End If

Next ctl

I hope this helps.

Please let me know how you egt on!!


Steve
Steve Jukes is offline   Reply With Quote
Old Oct 8th, 2002, 06:22 PM   #8
RogerC
Board Regular
 
Join Date: Mar 2002
Location: Phoenix, Arizona
Posts: 454
Default

Steve - I put the initialise code into a Private Sub UserForm_Initialize() and the other code in the UserForm_Activate Sub, but when I run it I get a 'Compile Error: Variable Not Defined on TextBox1'. Any idea what I may have done wrong?
RogerC is offline   Reply With Quote
Old Oct 11th, 2002, 04:14 AM   #9
Steve Jukes
Board Regular
 
Join Date: Apr 2002
Posts: 83
Default

RogerC,

Sorry for not getting back to you ealier but I have been out of the office for a few days.

The reason for your error is that you have to have a textbox named textbox1 and another textbox named textbox2. The 2 textboxes are there to record the height and width of the form before it maximises, ie the height and width it is when your are working on it in vb editor.

Hope this helps,

Steve
Steve Jukes is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On

Forum Jump


All times are GMT -4. The time now is 02:26 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes