Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. CenterParent in Windows 7? [modified]

CenterParent in Windows 7? [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++helpquestionlounge
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xpnctoc
    wrote on last edited by
    #1

    Hello. I posted this here because I noticed this issue first while working on a C++/CLI project. But it equally applies to C#.NET projects which makes me think it's a general .NET issue. Has anyone had troubles with the Form.StartPosition property value CenterParent in Windows 7? I know my invoking code is fine because I started this project on WinXP and everything was happy. Code like this in the main application form: MyForm^ f = gcnew MyForm(); f->Show(this); Despite the fact that I'm passing the reference to the parent in the Show() call, the child form shows up in the upper left corner rather than the center of the parent. Any ideas? Thanks in advance.

    modified on Wednesday, December 9, 2009 3:34 PM

    M 1 Reply Last reply
    0
    • X Xpnctoc

      Hello. I posted this here because I noticed this issue first while working on a C++/CLI project. But it equally applies to C#.NET projects which makes me think it's a general .NET issue. Has anyone had troubles with the Form.StartPosition property value CenterParent in Windows 7? I know my invoking code is fine because I started this project on WinXP and everything was happy. Code like this in the main application form: MyForm^ f = gcnew MyForm(); f->Show(this); Despite the fact that I'm passing the reference to the parent in the Show() call, the child form shows up in the upper left corner rather than the center of the parent. Any ideas? Thanks in advance.

      modified on Wednesday, December 9, 2009 3:34 PM

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      What happens if you explicitly set the Parent property of MyForm before calling ShowDialog()?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      X 1 Reply Last reply
      0
      • M Mark Salsbery

        What happens if you explicitly set the Parent property of MyForm before calling ShowDialog()?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        X Offline
        X Offline
        Xpnctoc
        wrote on last edited by
        #3

        First, I have to correct myself. The problem is in Show(), not ShowDialog(). I tried to explicitly set the parent ahead of time like this: MyForm^ f = gcnew MyForm(); f->Parent = this; f->Show(); Doing so gave me a runtime error at the line where I set the Parent property: ArgumentException: Top-level control cannot be added to a control.

        M 1 Reply Last reply
        0
        • X Xpnctoc

          First, I have to correct myself. The problem is in Show(), not ShowDialog(). I tried to explicitly set the parent ahead of time like this: MyForm^ f = gcnew MyForm(); f->Parent = this; f->Show(); Doing so gave me a runtime error at the line where I set the Parent property: ArgumentException: Top-level control cannot be added to a control.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Xpnctoc wrote:

          ArgumentException: Top-level control cannot be added to a control.

          Maybe set TopLevel to false? MyForm^ f = gcnew MyForm(); f->TopLevel = false; f->Parent = this; f->Show();

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          X 1 Reply Last reply
          0
          • M Mark Salsbery

            Xpnctoc wrote:

            ArgumentException: Top-level control cannot be added to a control.

            Maybe set TopLevel to false? MyForm^ f = gcnew MyForm(); f->TopLevel = false; f->Parent = this; f->Show();

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            X Offline
            X Offline
            Xpnctoc
            wrote on last edited by
            #5

            That didn't fly either. I didn't get an error, but the child window just plain didn't show up anywhere on the screen, taskbar, or anywhere else.

            M 1 Reply Last reply
            0
            • X Xpnctoc

              That didn't fly either. I didn't get an error, but the child window just plain didn't show up anywhere on the screen, taskbar, or anywhere else.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              It was worth a try... I don't know what your parent window is so I was just guessing, based on the fact there's a difference between "parent" windows and "owner" windows.

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              X 1 Reply Last reply
              0
              • M Mark Salsbery

                It was worth a try... I don't know what your parent window is so I was just guessing, based on the fact there's a difference between "parent" windows and "owner" windows.

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                X Offline
                X Offline
                Xpnctoc
                wrote on last edited by
                #7

                Well maybe that's part of my problem. I wasn't aware there is a difference. Could you explain that or provide a link that would elaborate on that more?

                M 1 Reply Last reply
                0
                • X Xpnctoc

                  Well maybe that's part of my problem. I wasn't aware there is a difference. Could you explain that or provide a link that would elaborate on that more?

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  I would start in the Form class properties[^] (Owner and Parent). Also maybe search on ".net parent vs owner" or similar. What are you using as a parent? A Win32 window (HWND) or another Form/Control?

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  X 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    I would start in the Form class properties[^] (Owner and Parent). Also maybe search on ".net parent vs owner" or similar. What are you using as a parent? A Win32 window (HWND) or another Form/Control?

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    X Offline
                    X Offline
                    Xpnctoc
                    wrote on last edited by
                    #9

                    The main application is a .NET Form.

                    M 1 Reply Last reply
                    0
                    • X Xpnctoc

                      The main application is a .NET Form.

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      it looks to me the only way to do this without making the form modal is manually...

                      MyForm^ f = gcnew MyForm();
                      f->StartPosition = FormStartPosition::Manual;
                      f->Location = System::Drawing::Point((this->Width - f->Width) / 2 + this->Location.X, (this->Height - f->Height) / 2 + this->Location.Y);
                      f->Show();
                      

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups