Multiple Forms
-
Hi, I need use two forms in application. Is some easy way exists? I do that in Delphi, but in C++/CLI Win Form app is something understandable. I was googling for some easy practise, but not found it. Is there something who help me with piece of code for two forms?
-
Hi, I need use two forms in application. Is some easy way exists? I do that in Delphi, but in C++/CLI Win Form app is something understandable. I was googling for some easy practise, but not found it. Is there something who help me with piece of code for two forms?
-
you can use multiple forms in C++/CLI. Just right click on your project and click "Add new Item..."
Don't be overcome by evil, but overcome evil with good
Sure, but I cant use (in example) in Form1 -> Form1.Visible = true; OK Form2.Show = true; it doesnt know Form2 (I maybe use :: ) I must include something to Form1?
-
Sure, but I cant use (in example) in Form1 -> Form1.Visible = true; OK Form2.Show = true; it doesnt know Form2 (I maybe use :: ) I must include something to Form1?
You can create 2 separate forms just as teejayem suggested, but if you want them completely independent of each other (i.e. Form2 is not a child of Form1), then you need to modify your .cpp file that opens your main form. This file contains your main loop, and probably has a line like Application::Run(gcnew Form1()); You would need to change this to create your Form1 and Form2 objects, show them, and then start your application. You might need a DoEvents loop, but there might be a way around that. Dybs
-
Sure, but I cant use (in example) in Form1 -> Form1.Visible = true; OK Form2.Show = true; it doesnt know Form2 (I maybe use :: ) I must include something to Form1?
-
You have to include the form2.h in your form1.h file for you to be able to use it
#include "Form2.h"
also "Show" isn't a property, it is a method. You shouldn't be trying to assign a boolean to it
Don't be overcome by evil, but overcome evil with good
Thank you, it works, but there is still little problem.
Form1::Visible = false; // I must create Form2, how can I do that? // Cannot use System::Windows::Forms::Form^ Form2 = gcnew System::Windows::Forms::Form; // It will be new form, but I need my Form2 Form2->Show(); // non-static member, I must use ->
-
Thank you, it works, but there is still little problem.
Form1::Visible = false; // I must create Form2, how can I do that? // Cannot use System::Windows::Forms::Form^ Form2 = gcnew System::Windows::Forms::Form; // It will be new form, but I need my Form2 Form2->Show(); // non-static member, I must use ->
I'm guessing that is because your varaible name is the same as your class name. so the compiler is thinking your trying to call a static method. Change your variable name to something more unique
System::Windows::Forms::Form^ myFrm2 = gcnew System::Windows::Forms::Form()
myFrm2->Show()
Don't be overcome by evil, but overcome evil with good
-
I'm guessing that is because your varaible name is the same as your class name. so the compiler is thinking your trying to call a static method. Change your variable name to something more unique
System::Windows::Forms::Form^ myFrm2 = gcnew System::Windows::Forms::Form()
myFrm2->Show()
Don't be overcome by evil, but overcome evil with good
Oh, thank you for your help. I was googling with "c++\cli" AND "#include"Form2.h"" and I found solution. It was that what you wrote. Same name Form2. THANK YOU
modified on Sunday, August 24, 2008 1:43 PM