Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Center Form in VB (VB 6)

    I ususally develop Office apps with VBA, but I'm using VB 6.0 (the version I have) to create a small EXE. Two questions:

    1. How do I center a form so that it displays in (or near) the middle of the screen? Is it better to place this code in the module where I Show the form, or does it belong in the Form.Activate (or Load) code?

    2. After creating the EXE, once I've run it, I can't delete it.... nor will recreating the EXE from the project over-write it. A message displays saying access is denied, the file is in use. This is a simple project: Sub Main displays the form, and an Exit button hides the form, and Sub Main unloads the form. Is there something additional that's required?

    Thanks,
    Richard Barrett

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Center Form in VB (VB 6)

    1) You can set the StartupPosition property of the form. Possible values:

    <table border=1><td>Constant</td><td>Value</td><td>Description</td><td>vbStartUpManual</td><td align=right>0</td><td>No initial setting specified.</td><td>vbStartUpOwner</td><td align=right>1</td><td>Center on the item to which the UserForm belongs.</td><td>vbStartUpScreen</td><td align=right>2</td><td>Center on the whole screen.</td><td>vbStartUpWindowsDefault</td><td align=right>3</td><td>Position in upper-left corner of screen.</td></table>
    See StartUpPosition Property

    2) If you have only hidden the main form, the application will still be in memory / use.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Center Form in VB (VB 6)

    Thank you. This is very helpful. I had code in Sub Main that should have centered the form, and that's where I unloaded the form. I know realize that Sub Main isn't running. I thought if there was a Sub Main, it would always run. Can you tell me something about that? I assumed that the form displayed because I used the Show method in Sub Main, but apparently it displayed because it is set as the Startup Form. How do I control that, meaning how do I not have this form display automatically and instead control everything through Sub Main?

    Regards,
    Richard

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Center Form in VB (VB 6)

    I don't know much about VB6 (and I don't have it available)

    The user should always return to the startup form and quit the application by closing this form (either directly or using code)

    Perhaps someone else can help you with the way Sub Main works.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Center Form in VB (VB 6)

    Do you have the form set as the startup object? Check the project properties and see.
    Charlotte

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Center Form in VB (VB 6)

    Thank you so much. I didn't realize there was such a thing as 'startup object.' it's quite simple!

    Thanks again
    Richard

  7. #7
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Center Form in VB (VB 6)

    Yes, the form was set as the startup object, presumably because it was the first object I created. I later added the module with Sub Main, but didn't realize that Sub Main didn't always have priority. I've now set Sub Main as the startup object, and things are functioning as I intend.

    Thanks again for your help.

Posting Permissions

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