CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    [RESOLVED] Problem with form not staying centered at start in VS 2012

    I am using Visual Studio 2012 (don't bash me for this). I have written MULTIPLE projects with splash screens and start forms.
    To center the screen when the project runs, I have just set the Start Position property on each of the forms to CENTER SCREEN.
    This way of doing things has worked for over 14 other projects. It was working on this latest project, but it keeps changing.
    I have NEVER had to code the start position of the screen in the Form load event!
    In my project properties, I have my startup form and splash screen set properly.
    The only thing I changed on the form was added extra Picture Boxes. Now, no matter what I do, the form will not hold the center screen at start up.
    What in the heck is going on?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problem with form not staying centered at start in VS 2012

    Does the screen have a parent window?

  3. #3
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Problem with form not staying centered at start in VS 2012

    To be truthful with you - I did not give my Form2 (the form with the problem) a parent window (not that I know of). Form1 is the splash screen. I'm sorry, how or where would I check for a parent window?

    All I did was add extra picture boxes to form2 and save the project. Something happened after I saved the project. To try to fix things, I added another form (form9) to the project. Then I copied all of the controls and moved the code to form9. Then I renamed the old form2 to form10, and renamed form9 to form2. Then deleted form10.
    I know, this wasn't a good thing to do - but I am desperate! I managed to restore the project properties so that the new form2 is opened after the splash screen is gone.
    Say, exactly how does the "complier" (I thinkclose the splash screen and open the main form?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problem with form not staying centered at start in VS 2012

    Are you displaying the form as non-modal with .Show(IWin32Window) or as a modal with .ShowDialog(IWin32Window)?

    In either case see if you are using the method overload that takes the IWin32Window param, and have the center style set, the form will be centered relative to the owner (parent) window.

    If you are using these overloads, try changing to the parameterless .Show() or .ShowDialog() versions.

    If you aren't, the try setting the owner window (e.g. .Show(this) or .ShowDialog(this)).

  5. #5
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Problem with form not staying centered at start in VS 2012

    I am not doing either of these things. Like I said, I have 14 other projects where I have done the exact same thing without issue. I create a project with 2 forms. In the project properties, I dedicate one of them to be a splash form and the other to be the start up form. Then I open the "View Application Events" using the button and paste in some reccommended code I found for timing the splash screen - works GREAT! After 5 seconds, the main form (my form2) opens. I have the "Start Position" property set to CENTER SCREEN just like I have the same property set for the splash screen. In the past (for 14 other projects - even now right up to this post, they ALL work) this is what I have done.
    Where do I find the OWNER window? Thank you for your help - you are sincerely appreciated!

  6. #6
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Problem with form not staying centered at start in VS 2012

    UPDATE: I decided to re-create the project from the ground up. First, I moved the original project off of the same drive, just in case. Then I did as I all ways do and started a new windows forms project. It automatically added the first form, so I added another. Just as I had done in the first project, I modified the first form with the exact same controls, background and settings. I then built the project in debug mode (any cpu) and ran it. Everything was working fine. I continued to modify the new project by re-creating the Form2 with the exact same settings and controls. At first, everything was great. I had mentioned that I had placed multiple picture boxes (15) on this form. No problems here.
    But when I surrounded one of the picture boxes with a rectangle (using Visual Basic Power Packs), re-built and ran the code - the form NO longer centered properly! I am creating a slot machine with certain playing card images. When the player wins, I wanted the rectangles to show which cards were winners. This whole project was working fine with 5 picture boxes and 5 rectangles. I'm going to try to fix Visual Basic Power Packs and determine if that is my issue. In any case - thank you again for your help. No need to reply. I am marking this as resolved. GOD Bless.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured