Consulting

Results 1 to 9 of 9

Thread: Minimizing UserForms

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Minimizing UserForms

    I have a UserForm that is displayed with vbModeLess. So it stays on the screen and can be moved around while the application does other things. It is closed by clicking on the X in the upper right corner. Many instances of this UserForm might be displayed at any time (with different "data"). To minimize screen clutter, I wish to allow the user to minimize individual instances. Before I add Min and Max command buttons and the necessary code, I wish to ask if there is a way to set up a UserForm such that the "standard window" buttons: Min; Normal; and Close (X) are availabe for UserForms (to the right of the Caption bar).

    Thanks

  2. #2

  3. #3
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    HI MWE,

    no there are not settings in the Userform properties to allow for such items, but as Jake has pointed out, there is a great example of how to do so using a little code - and this example will work with ShowModal set to 'false'.

    Scott
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  4. #4
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by DRJ
    See this KB Entry.
    this code does not do what the description says:
    1. Assuming that commandbutton1 is actually created, when clicked it unloads the form
    2. I can change that, but no button is created anywhere on the form.

  5. #5
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    MWE,

    the minimize button is on the frame (Titlebar) in the upper right.
    And commandbutton (Labeled 'Close') is created in the field of the userform.

    Leaving the commandbutton on the userform field to close the userform is optional, of course.
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  6. #6
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Scott
    MWE,

    the minimize button is on the frame (Titlebar) in the upper right.
    And commandbutton (Labeled 'Close') is created in the field of the userform.

    Leaving the commandbutton on the userform field to close the userform is optional, of course.
    Scott, thanks for you timely help.

    I figured out why this did not work initially. I was changing the UserForm caption programatically and that overwrote the buttons previously added. I moved the location where the proc FormatUserForm is called so the programatic revision to the UserForm caption occurs before the call that adds the buttons. I apologize for suggesting that the code did not work. BUT it does not do precisely/all that the description indicates. Once I sorted out the caption overwriting problem and got that working, I noticed that some features were still not working as advertised. So, I created an Excel test application. I used the code precisely as offered and placed it in the module locations indicated. Results:



    • two buttons are added to the frame:
      • a "minimize" button: this button does minimize the UserForm
      • a button that suggests "maximum" (icon is small square, left, right and bottom are gray, top is black): this button does not seem to do anything
    • when the UF is minimized,



      • the left button (was minimize) is now "return to original size", and that works as it should
      • the center button is the same as above and still does not do anything
    • commandbutton1 (labeled "Close" or otherwise) is not created anywhere.
    Neither of these issuses is a big problem for me, but suggests something is amiss. This may be a version issue. I am running MSForms 2.0 and tested this code in Excel2000, Word2000 and MSProject2000. Same results in each test.

  7. #7
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    MWE,

    glad you were able to get it working.
    It is funny that you mention the name change issue - I was just reading about a similar problem elsewhere, but the resolve seemed to be a bit much to me.

    Anyway, I am running this in XL2002 - I did not try it in 2000.
    I am not sure why the button does not create on the userform field for you...it could be a version issue or Ref issue (not sure).

    In any event, the max button doesn't seem to have any effect on several examples that I have seen (Jake's version, Ivan Moala's version, Colo's version, etc). I think that there is a reason for this, but I am hard pressed to remember it.

    I guess the question is now, will this solution work for you?
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  8. #8
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Scott: the solution in hand is adequate for now. As per you IM, I will look at other options as time permits.

    Many thanks.

  9. #9
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Hi MWE, the reason the Max button doesn't work is because it is coded like this. ie it disables the Max button.

    The KB code is not transparently evident that it doesn't do this as there are no flags used to show the controls.
    The other thing with the KB code is that it really just minimizes to the XL desk, not a true Min to taskbar. To do this requires a little more.

    If you look here

    http://www.xcelfiles.com/Userform_TaskBar.html

    It has a Workbook that has a technique to Min to the taskBar with an Icon
    It has set by default the Max button disabled ... to enable this just reset the flags

    '// 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_POPUP Or WS_MAXIMIZEBOX        '// and MaximizeBox
    The reason the Max button is disable is that it serves no purpose UNLESS you can resize all other controls within the userform. Have a look @ Steven's site for Formfun to do this ...

    http://www.bmsltd.ie/Excel/Default.htm
    Kind Regards,
    Ivan F Moala From the City of Sails

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •