How to link a button to a new window

Hi everyone,

back again. Obviously im new to C++ but i have big dreams :P

This is a pretty newbie question,

Anyway, i have been reading a book and i have been creating basic applications in Windows Form. I wanted to create a 2nd window but yeh I'm stuck there, and then once i created that 2nd window i want to link a button in the first window to the 2nd one.

So essentially i wan't to create a button in the first window (have done that already) When you press the button The 2nd window appears.

Any help is appreciated :)

Thank you heaps!


Kind Regards,

Vhorx
You mentioned Windows Forms. Are you programming in .Net? Or are you programming in unmanaged C++?
.Net at the moment. Should i be doing it in something else?
If you are in .Net and C++, you are programming in C++/CLI, in essence, a different language than C++.

In C#, you would just do:

1
2
Form2 f2 = new Form2();
f2.Show(); //If I recall correctly. 


Since I don't do C++/CLI, you should wait for a true expert to appear, but I think it goes something like this:

1
2
Form2^ f2 = gcnew Form2();
f2->Show();
Thanks for the suggestion. It didnt work. Un less I did it wrong hehe. Any other suggestions?
Error messages? Run-time or compile-time?
This is what i get when i use that after double clicking the button and putting my code in.

1>------ Build started: Project: Tester, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1> Form2.cpp
1> Tester.cpp
1>c:\users\admin\documents\visual studio 2010\projects\tester\tester\Form1.h(80): error C2065: 'Form2' : undeclared identifier
1>c:\users\admin\documents\visual studio 2010\projects\tester\tester\Form1.h(80): error C2065: 'f2' : undeclared identifier
1>c:\users\admin\documents\visual studio 2010\projects\tester\tester\Form1.h(80): error C2061: syntax error : identifier 'Form2'
1>c:\users\admin\documents\visual studio 2010\projects\tester\tester\Form1.h(81): error C2065: 'f2' : undeclared identifier
1>c:\users\admin\documents\visual studio 2010\projects\tester\tester\Form1.h(81): error C2227: left of '->show' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is the code that im using as well.

1
2
3
4
5
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 Form2^ f2 = new Form2();
				 f2 -> show();
			 }


Am i doing the above correctly?

Also what do you mean by runtime or compile time, assuming it is what i think it is, it doesn't compile correctly.

Thanks :)
You probably need to include the header of 'Form2'
Topic archived. No new replies allowed.