Question about User Form Window Size on Chip Petersons Site

B

Brian

I have a User Form that I need to adjust to fit the users computer. So far I
not found anyway to get the User Form Window to Adjust. I can adjust the User
Form sixe, but the Main Window the Form located is in is still bigger than
the Screen.

I saw on Chip Petersons site exactly what I need. His code allows complete
control over the User Form just as if it was a regular window.

Can anyone help me with this code?
http://www.cpearson.com/Excel/formcontrol.aspx
 
P

Peter T

There are various ways, this is probably the easiest although it may hide
the task bar

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 ShowWindow Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

Private Const SW_MAXIMIZE As Long = 3

Private Sub UserForm_Activate()
Dim hWnd As Long
With Me
.Caption = Rnd()
hWnd = FindWindow("ThunderDFrame", .Caption)
.Caption = "Hello"
End With
ShowWindow hWnd, SW_MAXIMIZE
End Sub

Regards,
Peter T
 
B

Brian

Can you please explain exactly what this code is going to do?

My Biggest problem is that my User Form only works on my Display. When I try
and use it on any other computer Not only is the User Form to big, but the
Main Window the User Form is in goes completely off the screen.

I want the User Form Window to act just like any other Window. With Min, Max
& Resize, just like a reqular window would do.

Thanks for your response.
 
D

Dave Peterson

First, it's Chip Pearson's site.

Second, Chip's code resizes the userform--not the controls on the userform (is
that what "main window" means???). You'll have to take care of that
yourself--for each control that you want to resize.

Third, I'd weasel out and make the userform fit the worst display settings
possible. Maybe even redesign it to show less stuff (use multipages
instead????).
 
C

Chip Pearson

Peter T has provided the code you need, but I would suggest that you
rethink whether you really want to always open the form such that it
covers the entire screen. As an end user, I would find that rather
annoying and frankly a bit rude. I would suggest that you use the code
on my web site to add a maximize button to the form's caption bar,
enable the form to be resized, and allow the user to maximize the form
if he so desires.

If you need to support multiple screen resolutions, you'll run into
problems when maximizing or resizing the form. Maximizing a form isn't
going to do the requisite resizing and/or repositioning the controls
that reside on the form. For example, suppose you have a form with
four textboxes in the upper region of the form. When you resize or
maximize the form, these controls will not move or resize themselves
to fit well within the new form size. Instead, they will remain in the
same position and have the same size as they had originally. The only
thing you get is a much larger form comprised almost completely by
empty space.

It is possible, but quite difficult, to resize and/or reposition the
controls on a form to make them look good on the expanded form. (This
type of thing is handled very very well in the WPF/XAML/NET3.5
framework.)

When you design a form that is to be used on monitors that may be of
different sizes and aspect ratios, it is best to develop for the
smallest for that you will support and leave the expanded spaces on
higher res screens alone. It is generally save to assume that your
users will be on 1024 x 1200 resolution, although you can't really
make any assumption about the aspect ratio -- it could be 4:3 for
"normal" monitors or 16:9 or 16:10 on widescreens.
I saw on Chip Petersons site

Who?

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 
P

Peter T

Did you try it, it should maximize the window.

It doesn't include code to add the min/max buttons & enable resize but I
assume that's already covered by Chip Pearson's examples.

Regards,
Peter T
 
P

Peter T

Sorry, omitted an API declaration (although you'll probably already have
that and have obtained the form's handle)

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Peter T
 
P

Peter T

Chip Pearson said:
Peter T has provided the code you need, but I would suggest that you
rethink whether you really want to always open the form such that it
covers the entire screen. As an end user, I would find that rather
annoying and frankly a bit rude.

Totally agree. Sometimes a maximized form is used as a splash screen, not
that I like those much either. The way posted was only to demo.

Regards,
Peter T
 
B

Brian

Believe it or not I still have an old 17" Flat Panel Monitor, that I keep for
a back up just incase I need it. I think if I use the Code on your Page to
adjust the Outer User Form Window and add the Min, Max & Resize option. Then
adjust the User Form to fit that on the 17" Monitor that should work.

What do you think?

By the way Sorry about the last Name Error, I had just finished reading a
post by Dave Peterson and got confused. Of course that seems to be happening
alot more & more these days.



Chip Pearson said:
Peter T has provided the code you need, but I would suggest that you
rethink whether you really want to always open the form such that it
covers the entire screen. As an end user, I would find that rather
annoying and frankly a bit rude. I would suggest that you use the code
on my web site to add a maximize button to the form's caption bar,
enable the form to be resized, and allow the user to maximize the form
if he so desires.

If you need to support multiple screen resolutions, you'll run into
problems when maximizing or resizing the form. Maximizing a form isn't
going to do the requisite resizing and/or repositioning the controls
that reside on the form. For example, suppose you have a form with
four textboxes in the upper region of the form. When you resize or
maximize the form, these controls will not move or resize themselves
to fit well within the new form size. Instead, they will remain in the
same position and have the same size as they had originally. The only
thing you get is a much larger form comprised almost completely by
empty space.

It is possible, but quite difficult, to resize and/or reposition the
controls on a form to make them look good on the expanded form. (This
type of thing is handled very very well in the WPF/XAML/NET3.5
framework.)

When you design a form that is to be used on monitors that may be of
different sizes and aspect ratios, it is best to develop for the
smallest for that you will support and leave the expanded spaces on
higher res screens alone. It is generally save to assume that your
users will be on 1024 x 1200 resolution, although you can't really
make any assumption about the aspect ratio -- it could be 4:3 for
"normal" monitors or 16:9 or 16:10 on widescreens.
I saw on Chip Petersons site

Who?

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




I have a User Form that I need to adjust to fit the users computer. So far I
not found anyway to get the User Form Window to Adjust. I can adjust the User
Form sixe, but the Main Window the Form located is in is still bigger than
the Screen.

I saw on Chip Petersons site exactly what I need. His code allows complete
control over the User Form just as if it was a regular window.

Can anyone help me with this code?
http://www.cpearson.com/Excel/formcontrol.aspx
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top