Hai Programmers,
my title should say it all but im looking for a function where another form
(wich pops up when a button in first form gets pressed) will pop up at the top right
of the first form.
(Would be best with "StartPosition" "Manuel" i guess)

(Im using Microsoft Visual Studio 2010)

Sorry if this is hard to understand, but english isn't my motherlanguage.

I assume you are using Winforms? There's a property of the form called ClientRectangle. It contains the height and the width of the form. Using those values, do a calculation for where to place the upper left corner of the 2nd form.

SetBouds() will move the window to the x and y coordinates you specify.

There is probably more than one way to do it, but this is how I solved the problem.

1. In Form2 add a public data member of type Rectangle, e.g. Rectangle r; 2. In Form1, in the OnButtonClick event handler

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 Form2^ f2 = gcnew Form2;
                 f2->r = ClientRectangle; // set the Rectangle object in Form2
                 this->Hide();
                 f2->ShowDialog();
                 this->textBox1->Text = f2->GetTextBoxString();
                 this->Show();
             }

3. In Form2,

private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {

                 SetBounds(r.Right+1,r.Top,r.Height,r.Width);
             }

Edited 5 Years Ago by Ancient Dragon: n/a

SetBouds () will move the window to the x and y coordinates you specify.

There is probably more than one way to do it, but this is how I solved the problem.

1. In Form2 add a public data member of type Rectangle, e.g. Rectangle r; 2. In Form1, in the OnButtonClick event handler

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 Form2^ f2 = gcnew Form2;
                 f2->r = ClientRectangle; // set the Rectangle object in Form2
                 this->Hide();
                 f2->ShowDialog();
                 this->textBox1->Text = f2->GetTextBoxString();
                 this->Show();
             }

3. In Form2,

private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {

                 SetBounds(r.Right+1,r.Top,r.Height,r.Width);
             }

Thank you so much :)
But could you please post all code of Form1.h and Form2.h ?
Would be quite helpfull for me :)

The rest of those two header files were generated by VC++ 2010. I posted all the code that I changed, except that you need to include Form2.h at the beginning of Form1.h

Uhm, okay.
But could you show me the part where you defined "Rectangle r;"
I'm having problems with it.

(Form1.h and Form2.h is still appreciate)
Thanks for your help though.

Well, there are lots of places in Form2.h to put it, just make it public

public ref class Form2 : public System::Windows::Forms::Form
	{
	public:
		Form2(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
        Rectangle r;

Well, there are lots of places in Form2.h to put it, just make it public

public ref class Form2 : public System::Windows::Forms::Form
	{
	public:
		Form2(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
        Rectangle r;

Oh, your code actually works well.
But In combinating with my project it somehow doesn't work, that just weird.
Thanks anyways :)

If you can (e.g. if you have permissions to do so) zip up your project and attach it so that we can find out why it doesn't work for you. Delete the debug folders and other compiler-generated compile-time files such as *.obj and *.sdf

I think you creted the wrong kind of project. My compiler said it is an unmanaged program attempting to use managed code system::Windows::Form. You should have created a CLR/C++ Windows Forms project.

Edited 5 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.