OK, I made two Windows Forms Applications (Look images below)
Step 1: http://img245.imageshack.us/img245/8227/78636770.jpg
Step 2: http://img408.imageshack.us/img408/808/48168956.jpg
Well, as you see at "step 1" there is some text (blured) and the Next button in bottom left corner. I would like to know how to make that when I click Next button it will send me to Step 2? Step 1 application and step 2 application are 2 different projects... Should i merge them together first (how to do this)?

However once again: I want when I click button Next at Step 1 it open me application of Step 2.

I tryed to describe my problem as much as possible... However, since I am not exprert programer I may missed some important things, so fell free to ask here.

Thanks!

Yes, merge them, all you have to do as far as i know is rename the second form to "Form2" and copy it to the first project. Once you've done that, linking them together isn't too hard.

Try that first.

Well, I think I have merged 'em but I am not really sure if it's all right...
Here is Screen Shot of my project now (it was project for Step 1 before)
When I have First Step tab selected:
http://img243.imageshack.us/img243/7155/42947319.jpg
When I have Second Step tab selected:
http://img67.imageshack.us/img67/9248/44445701.jpg
It gets compiled without errors.

So if it's nicely merged now, what to do if I want when I click Next button at step 1 it send me to step 2?

Looks good to me.

Okay, now at the top up your header file Form1.h, add the code:

#include "Form2.h"

and to hide the current form and open the new one, place this code in the event handler of the Next button on Form1:

Form2 ^secondForm = gcnew Form2();
this->Hide();
secondForm->Show();

Be weary, one of your forms is named form1 and the other Form2, remember C++ is case sensitive.

Hm, I added #include line to form1.h. Now beggining of code in form1.h looks like

#include "form2.h"
#pragma once

...

But I got no clue what Event Handler is...
That's the code u told me to add into form1 next button's event handler

Form2 ^secondForm = gcnew Form2();
this->Hide();
secondForm->Show();

Could you tell me more exactly in what file and in what place in that file I should copy that code? Or just what event handler is?

Could you tell me more exactly in what file and in what place in that file I should copy that code? Or just what event handler is?

When you double click your button in designer mode, it takes you to the code that's executed once it's pressed, It would look something like this:

private: System::Void mybutton_Click(System::Object^  sender, System::EventArgs^  e) {
    Form2 ^secondForm = gcnew Form2();
    this->Hide();
    secondForm->Show();
}

Edited 7 Years Ago by William Hemsworth: n/a

I get those error results

Build Log

Rebuild started: Project: source, Configuration: Debug|Win32


Command Lines

Creating temporary file "c:\Users\Kustrle\Desktop\Windows 7 Home Simple\step_01\source\Debug\RSP00002330961364.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\source.pch" /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /Zi /clr:pure /TP /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"

".\source.cpp"

".\form2.cpp"

".\AssemblyInfo.cpp"
]
Creating command line "cl.exe @"c:\Users\Kustrle\Desktop\Windows 7 Home Simple\step_01\source\Debug\RSP00002330961364.rsp" /nologo /errorReport:prompt"
Creating temporary file "c:\Users\Kustrle\Desktop\Windows 7 Home Simple\step_01\source\Debug\RSP00002430961364.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Yc"stdafx.h" /Fp"Debug\source.pch" /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /Zi /clr:pure /TP /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"

".\stdafx.cpp"
]
Creating command line "cl.exe @"c:\Users\Kustrle\Desktop\Windows 7 Home Simple\step_01\source\Debug\RSP00002430961364.rsp" /nologo /errorReport:prompt"
Output Window

Compiling...
stdafx.cpp
Compiling...
source.cpp
.\source.cpp(6) : error C2059: syntax error : 'namespace'
.\source.cpp(6) : error C2238: unexpected token(s) preceding ';'
.\source.cpp(19) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\kustrle\desktop\windows 7 home simple\step_01\source\Form1.h(24)' was matched
form2.cpp
AssemblyInfo.cpp
Generating Code...
Results

Build log was saved at "file://c:\Users\Kustrle\Desktop\Windows 7 Home Simple\step_01\source\Debug\BuildLog.htm"
source - 3 error(s), 0 warning(s)

My source.cpp file contains:

// source.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace source;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
}

My form1.h contains:

1.  #include "form2.h"
2.  #pragma once
3.   
4.   
5.  namespace source {
6.   
7.  using namespace System;
8.  using namespace System::ComponentModel;
9.  using namespace System::Collections;
10. using namespace System::Windows::Forms;
11. using namespace System::Data;
12. using namespace System::Drawing;
13.  
14. /// <summary>
15. /// Summary for Form1
16. ///
17. /// WARNING: If you change the name of this class, you will need to change the
18. /// 'Resource File Name' property for the managed resource compiler tool
19. /// associated with all .resx files this class depends on. Otherwise,
20. /// the designers will not be able to interact properly with localized
21. /// resources associated with this form.
22. /// </summary>
23. public ref class Form1 : public System::Windows::Forms::Form
24. {
25. public:
26. Form1(void)
27. {
28. InitializeComponent();
29. //
30. //TODO: Add the constructor code here
31. //
32. }
33.  
34. protected:
35. /// <summary>
36. /// Clean up any resources being used.
37. /// </summary>
38. ~Form1()
39. {
40. if (components)
41. {
42. delete components;
43. }
44. }
45. private: System::Windows::Forms::Button^ button1;
46. private: System::Windows::Forms::Button^ button2;
47. private: System::Windows::Forms::Button^ button3;
48. private: System::Windows::Forms::PictureBox^ pictureBox1;
49. private: System::Windows::Forms::Label^ label1;
50. private: System::Windows::Forms::PictureBox^ pictureBox2;
51. private: System::Windows::Forms::PictureBox^ pictureBox3;
52.  
53. protected: 
54.  
55. protected: 
56.  
57. protected: 
58.  
59. protected: 
60.  
61. protected: 
62.  
63. protected: 
64.  
65.  
66.  
67. protected: 
68.  
69. protected: 
70.  
71. protected: 
72.  
73.  
74. protected: 
75.  
76.  
77. private:
78. /// <summary>
79. /// Required designer variable.
80. /// </summary>
81. System::ComponentModel::Container ^components;
82.  
83. #pragma region Windows Form Designer generated code
84. /// <summary>
85. /// Required method for Designer support - do not modify
86. /// the contents of this method with the code editor.
87. /// </summary>
88. void InitializeComponent(void)
89. {
90. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
91. this->button1 = (gcnew System::Windows::Forms::Button());
92. this->button2 = (gcnew System::Windows::Forms::Button());
93. this->button3 = (gcnew System::Windows::Forms::Button());
94. this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
95. this->label1 = (gcnew System::Windows::Forms::Label());
96. this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
97. this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
98. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
99. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->BeginInit();
100.    (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->BeginInit();
101.    this->SuspendLayout();
102.    // 
103.    // button1
104.    // 
105.    this->button1->Location = System::Drawing::Point(12, 327);
106.    this->button1->Name = L"button1";
107.    this->button1->Size = System::Drawing::Size(75, 23);
108.    this->button1->TabIndex = 0;
109.    this->button1->Text = L"Next";
110.    this->button1->UseVisualStyleBackColor = true;
111.    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
112.    // 
113.    // button2
114.    // 
115.    this->button2->DialogResult = System::Windows::Forms::DialogResult::Cancel;
116.    this->button2->Location = System::Drawing::Point(93, 327);
117.    this->button2->Name = L"button2";
118.    this->button2->Size = System::Drawing::Size(75, 23);
119.    this->button2->TabIndex = 1;
120.    this->button2->Text = L"Cancel";
121.    this->button2->UseVisualStyleBackColor = true;
122.    // 
123.    // button3
124.    // 
125.    this->button3->Location = System::Drawing::Point(174, 327);
126.    this->button3->Name = L"button3";
127.    this->button3->Size = System::Drawing::Size(75, 23);
128.    this->button3->TabIndex = 2;
129.    this->button3->Text = L"Help";
130.    this->button3->UseVisualStyleBackColor = true;
131.    this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
132.    // 
133.    // pictureBox1
134.    // 
135.    this->pictureBox1->BackColor = System::Drawing::Color::Transparent;
136.    this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image")));
137.    this->pictureBox1->Location = System::Drawing::Point(412, 298);
138.    this->pictureBox1->Name = L"pictureBox1";
139.    this->pictureBox1->Size = System::Drawing::Size(166, 37);
140.    this->pictureBox1->TabIndex = 3;
141.    this->pictureBox1->TabStop = false;
142.    // 
143.    // label1
144.    // 
145.    this->label1->BackColor = System::Drawing::Color::Transparent;
146.    this->label1->Font = (gcnew System::Drawing::Font(L"Segoe UI", 9.5F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
147.    static_cast<System::Byte>(238)));
148.    this->label1->ForeColor = System::Drawing::SystemColors::ControlLightLight;
149.    this->label1->Location = System::Drawing::Point(90, 128);
150.    this->label1->Name = L"label1";
151.    this->label1->Size = System::Drawing::Size(205, 136);
152.    this->label1->TabIndex = 4;
153.    this->label1->Text = L"Text...";
154.    this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
155.    // 
156.    // pictureBox2
157.    // 
158.    this->pictureBox2->BackColor = System::Drawing::Color::Transparent;
159.    this->pictureBox2->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox2.Image")));
160.    this->pictureBox2->Location = System::Drawing::Point(402, 328);
161.    this->pictureBox2->Name = L"pictureBox2";
162.    this->pictureBox2->Size = System::Drawing::Size(166, 37);
163.    this->pictureBox2->TabIndex = 5;
164.    this->pictureBox2->TabStop = false;
165.    // 
166.    // pictureBox3
167.    // 
168.    this->pictureBox3->BackColor = System::Drawing::Color::Transparent;
169.    this->pictureBox3->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox3.Image")));
170.    this->pictureBox3->Location = System::Drawing::Point(93, 95);
171.    this->pictureBox3->Name = L"pictureBox3";
172.    this->pictureBox3->Size = System::Drawing::Size(166, 37);
173.    this->pictureBox3->TabIndex = 6;
174.    this->pictureBox3->TabStop = false;
175.    // 
176.    // Form1
177.    // 
178.    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
179.    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
180.    this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage")));
181.    this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
182.    this->ClientSize = System::Drawing::Size(584, 362);
183.    this->Controls->Add(this->pictureBox3);
184.    this->Controls->Add(this->pictureBox2);
185.    this->Controls->Add(this->label1);
186.    this->Controls->Add(this->pictureBox1);
187.    this->Controls->Add(this->button3);
188.    this->Controls->Add(this->button2);
189.    this->Controls->Add(this->button1);
190.    this->DoubleBuffered = true;
191.    this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
192.    this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
193.    this->Location = System::Drawing::Point(348, 210);
194.    this->MaximizeBox = false;
195.    this->MinimizeBox = false;
196.    this->Name = L"Form1";
197.    this->ShowIcon = false;
198.    this->ShowInTaskbar = false;
199.    this->StartPosition = System::Windows::Forms::FormStartPosition::Manual;
200.    this->Text = L"Text";
201.    this->TopMost = true;
202.    this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
203.    (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
204.    (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit();
205.    (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->EndInit();
206.    this->ResumeLayout(false);
207.     
208.    }
209.    #pragma endregion
210.    private: System::Void richTextBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
211.    }
212.    private: System::Void maskedTextBox1_MaskInputRejected(System::Object^ sender, System::Windows::Forms::MaskInputRejectedEventArgs^ e) {
213.    }
214.    private: System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
215.    }
216.     
217.    private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
218.    }
219.    private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
220.    }
221.    private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
222.    }
223.    private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
224.    }
225.     
226.    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
227.    form2 ^secondForm = gcnew form2();
228.    this->Hide();
229.    secondForm->Show();
230.
}

Edited 3 Years Ago by happygeek: fixed formatting

You're missing two sets of end curly braces, change the end to this:

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
                  form2 ^secondForm = gcnew form2();
                  this->Hide();
                  secondForm->Show();
            }
      };
}

Try to keep your formatting tidy, hope this helps.

End of my form1.h looks like this

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
		 }

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 form2 ^secondForm = gcnew form2();
                 this->Hide();
                 secondForm->Show();
            }
      };
}

It compiles nice, without errors. But when I start application, I can click next button as much times as I want and nothing moves - just as before.

Edited 7 Years Ago by kustrle: n/a

Hm, now it works. It automatialy added me one more line of code to end

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

I also added

form2 ^secondForm = gcnew form2();
                 this->Hide();
                 secondForm->Show();

Under that line so now my end looks like

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 form2 ^secondForm = gcnew form2();
                 this->Hide();
                 secondForm->Show();
            }
	  private: System::Void button1_Click_1(System::Object^  sender, System::EventArgs^  e) {
form2 ^secondForm = gcnew form2();
                 this->Hide();
                 secondForm->Show();			  
			   }
};
}

Thank you very much! You helped me.

This question has already been answered. Start a new discussion instead.