开发者

Is there a way to open a child form in exactly the same place as the parent form?

开发者 https://www.devze.com 2022-12-25 00:35 出处:网络
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 whi开发者_如何学编程ch ruins the effect.

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 whi开发者_如何学编程ch ruins the effect. If there a way to make it open wherever the first form may be?

I am using visual studio, in C++


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();


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消