Updated FormFun example

Following Jamie Collins’ prompting, I’ve just released an update to my FormFun example workbook. This workbook demonstrates how to modify a userform’s window styles to make it sizable, have an icon, show in the task bar, disable the [x] close button etc. The example can be downloaded from http://www.oaltd.co.uk/Excel. It includes a class module to encapsulate the Windows API calls that can be copied straight into your projects and used with just a few extra lines. For example, to create a sizable userform with a custom icon that shows in the task bar, you’d add the class module to your project and include the following code in the form:

Private Sub UserForm_Activate()

    Dim clsFormChanger As CFormChanger
   
    Set clsFormChanger = New CFormChanger
   
    clsFormChanger.Sizeable = True
    clsFormChanger.ShowIcon = True
    clsFormChanger.IconPath = “C:MyPathMyIcon.ico”
    clsFormChanger.ShowTaskBarIcon = True
   
    Set clsFormChanger.Form = Me

End Sub

Private Sub UserForm_Resize()
    ‘Some code to reposition all the controls
   ‘according to the form’s height and width,
   ‘given by Me.InsideHeight and Me.InsideWidth

End Sub

Enjoy

Stephen Bullen

Posted in Uncategorized

8 thoughts on “Updated FormFun example

  1. Hi,
    I have been playing around with this, it’s really good. Again, thanks very much, it will be a tremendous help. I have one question though:

    On your form the ok button has a blank label control behind it, looking at the comments it says it’s there to over come the button control showing white edges (after a form resize/reposition).
    My question is, would .repaint not work. I tried to recreate the white thing but couldn’t, I added .repaint, and removed the label, with no noticeable difference. Why choose this method?

  2. Yes .Repaint would work, but I found it caused lots of flickering. Without the label or .Repaint, when resizing the dialog by small amounts, the left edge of the OK button was often left drawn – leaving a trail of them. Adding the label forced just that section of the form to be redrawn, instead of the whole thing.

    Regards

    Stephen Bullen

  3. thak you????? god I’m a bad speller/typer!

    Just noticed something which may or may not be help full.
    (or might just be me being thick! – highly likely)

    [xl 97, 2k pro os]
    when running:

    Private Sub UserForm_Initialize()
    Set mclsFormChanger = New CFormChanger
    mclsFormChanger.Modal = False
    mclsFormChanger.ShowMinimizeBtn = True

    the form will not become modeless. stepping through, the calls are made and the Let prop is set to False, but the form does not become modeless. The Minimise btn does show and work as expected:

    UserForm_Activate() works as expected.

    Is this the expect behaviour, have I missed something obvious?

  4. Ross – Setting Modal to False might only work after the form is shown, as that is part of the display action. So it’s probably just a case of the sequence of things happening.

    Regards

    Stephen Bullen

  5. ok, i get that i think:

    –> call event
    –> calls modal = flase
    –> sets the xlmain to “active” (or whatever)
    –> then the form is loaded
    –> thus negating the xlmain bit

    or something similar

    makes sense:

    cheers very much Stephen

  6. I have tried the above code. After I close the form, then Excel was hang on. What’s the problems?

    Regards,

    Le Van Duyet


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.