CenterParent in Windows 7? [modified]
-
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
-
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
What happens if you explicitly set the Parent property of MyForm before calling ShowDialog()?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What happens if you explicitly set the Parent property of MyForm before calling ShowDialog()?
Mark Salsbery Microsoft MVP - Visual C++ :java:
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.
-
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.
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:
-
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:
-
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.
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:
-
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:
-
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?
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:
-
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:
-
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: