tags:

views:

65

answers:

4

I have one form opening a second form which is meant to look like it's replaced the first form but it opens a bit to the right and down which ruins the effect. If there a way to make it open wherever the first form may be?

I am using visual studio, in C++

A: 

Have you tried messing with the Height/Width/Location of the new Form?

I don't know for sure, but I imagine that you could grab the location and size of the original form, and when creating the new Form, set it's Location and size to the same values, just before you call "Show" (or set Visible to true) on the new Form.

Andy White
Hmmm... not sure if this is possible in C++-based Winforms. I think it can be easily done with .NET winforms though.
Andy White
If you're using Windows Forms (which is to say, the .NET wrapper implementation for the Win32 window management API), you can do this regardless of language. C++/CLI doesn't impose any new restrictions on the WinForms API to the best of my knowledge, although its syntax for dealing with them is often much more complicated than the "pure" .NET languages.
Dan Story
A: 

The "opening a bit to the right and down" makes it sound like you've placed the new window at the top-left corner of the parent's client area. You need to take the border width into account to get them to match up.

Jerry Coffin
"Opening to the right and down" is also a fair description of the window manager's default position for newly-created top-level windows which were not shown using SW_SHOWMAXIMIZED or SW_SHOWMINIMIZED.
Dan Story
@Dan: I hadn't considered that -- you raise a good point.
Jerry Coffin
+2  A: 

Set the new form's StartPosition to Manual and give it the same Size and Location:

  Form2^ frm = gcnew Form2;
  frm->StartPosition = FormStartPosition::Manual;
  frm->Location = this->Location;
  frm->Size = this->Size;
  frm->Show();
Hans Passant
A: 

eeeeeeee got it! thanks for all your help guys, and that code worked perfectly.

Ruth