I have Created a Form1. On this Form I have a button that opens Form2 like this:

Form2 ^form2 = gcnew Form2;
form2->Show();

Now if I click on Form1, Form2 will "dissapear" under Form1.
What I wonder is, if it is possible to click on Form1, but stil,l Form2 will be seen.

Example will be if I have some buttons on Form1, I don´t want Form2 to "dissapear" under Form1 if I press these buttons.

Give form2 a topmost value so it always appears above other windows, or open it as a dialog (you wont be able to use form1 until form2 is closed).

I don´t want to open Form2 as a dialogbox like this as I will press buttons on Form1 when Form2 is opened:

Form2 ^form2 = gcnew Form2;
form2->ShowDialog();

I don´t know how it is possible to give Form2 a topmost value or what this meens.
However this sounds like something that I am after.
Thanks...

Give form2 a topmost value so it always appears above other windows, or open it as a dialog (you wont be able to use form1 until form2 is closed).

Try: form2->TopMost::set(true); Before opening the window.

This worked great.
Thank you for this.

When putting the below code to the Load Event of the Form, this form will always be on top of Form1 even if I click on Form1. This is good.
One problem that I have discovered is that if I have Form2 opened and now Ex: opens WordPad, Paint etc... These "Forms" will startup/ be under Form2 also.
I dont know why this is happening and what could be done about that.

form2->TopMost::set(true);

Try: form2->TopMost::set(true); Before opening the window.

I dont know why this is happening and what could be done about that.

form2->TopMost::set(true);

It is happening because that is what the above line does.
Maybe you could instead try to use the Form2's Owner property, i.e.

Form2 ^form2 = gcnew Form2;
// Form1 owns the form2 ...
form2->Owner::set(this);
form2->Show();

That way Form2 stays above Form1, but won't get in the way of any other windows.

This worked. So if I understand the code right, what happens is that Form1 is "giving" some information to Form2 and telling that Form1 owns Form2 and then Form2 is opening.
With ´Owner´, that meens that Form2 will be seen in front of Form1

It is happening because that is what the above line does.
Maybe you could instead try to use the Form2's Owner property, i.e.

Form2 ^form2 = gcnew Form2;
// Form1 owns the form2 ...
form2->Owner::set(this);
form2->Show();

That way Form2 stays above Form1, but won't get in the way of any other windows.

In brief, the code establishes the ownership of Form2 i.e. Form1 is said to own Form2.
Quoting MSDN here:

* An owned window is always above its owner in the z-order.
* The system automatically destroys an owned window when its owner is destroyed.
* An owned window is hidden when its owner is minimized.

http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#owned_windows

It make sense. Thanks for info.

In brief, the code establishes the ownership of Form2 i.e. Form1 is said to own Form2.
Quoting MSDN here:

* An owned window is always above its owner in the z-order.
* The system automatically destroys an owned window when its owner is destroyed.
* An owned window is hidden when its owner is minimized.

http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#owned_windows

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.