locked
I need help please RRS feed

  • Question

  • Hi, I am using the visual studio 2010. I have a project on how to create ATM machine, the main problem i don't know how to open a new form from the current form. for example if i am working on a form, how can i open a new form by just clicking a button and hide the previous one.

    i've seen the syntx for this on visual studio 2008, it was like " Form2.Show();" and then " me.hide(); ", and i've tried this many times but it doesn't work. so can you just help with this?

    Thanks

    Friday, December 10, 2010 3:16 AM

Answers

  • I finally solve this problem, thanks for help anyway

     

    	 {
    					 hello::Form2;
    Form2 ^ dlg = gcnew Form2;
    
      dlg->ShowDialog();
    } 

    • Marked as answer by Shady Enany Friday, December 17, 2010 2:14 AM
    Sunday, December 12, 2010 11:10 PM

All replies

  • Hi, I am using the visual studio 2010. I have a project on how to create ATM machine, the main problem i don't know how to open a new form from the current form. for example if i am working on a form, how can i open a new form by just clicking a button and hide the previous one.
     
    i've seen the syntx for this on visual studio 2008, it was like " Form2.Show();" and then " me.hide(); ", and i've tried this many times but it doesn't work. so can you just help with this?
    Show your code, and describe what "doesn't work". The first step is always to write code that will compile.
     

    David Wilkinson | Visual C++ MVP
    Friday, December 10, 2010 4:13 AM
  • private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                     int password;
                     int i;
                     password = Convert::ToInt32(textBox1->Text);
                     if (password == 123)
                     {
                     label1->Text = "Correct password";
                    Form2->Show(); // the main problem is in this syntax, am not sure am using the correct syntax.
                    Me->Hide();

                     }
                     else if (password != 123)
                     {
                     label1->Text = "Wrong password, Please Try Again";
                     }
                     else
                     {
                     for (i=0;i>3;i++)
                     {
                     label1->Text = "Wrong password, Please exit";
                     }
                     }
                 }
        private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
                     this->Close();
                 }
    };
    }

     

    Here is my code, i just add a new form and i define it as #include "Form2.h"

    but it still doesn't work. can you help with this?

    thanks for your reply anyway.

    Friday, December 10, 2010 6:21 PM
  • private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
                     int password;
                     int i;
                     password = Convert::ToInt32(textBox1->Text);
                     if (password == 123)
                     {
                     label1->Text = "Correct password";
    Form2->Show(); // the main problem is in this syntax,
    Well, yes. This code does not compile, right? Remember, you are supposed to say what "doesn't work". In the case of compiler error this means posting the error message itself, and indicating the line of code it refers to.
     
    The reason it does not work is that Form2 is your class name, not an object. You need to do
     
    Form2^ form2 = gcnew Form2();
    form2->Show();
    this->Hide(); // not Me
     
    Does it compile now?
     
    Bt the way, in future please use a meaningful subject for your post. "I need help" does not say anything; everybody who asks questions needs help.
     

    David Wilkinson | Visual C++ MVP
    Friday, December 10, 2010 7:02 PM
  • now i started it all over again.. i added 2 forms (form1 and form2), 2 textboxes, 2 labels, and i wrote the following code:

     

    #pragma endregion
      private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
            int username; 
    int password; password = Convert::ToInt32(textBox2->Text); username = Convert::ToInt32(textBox1->Text); if (textBox1->Text== "abc" && textBox2->Text= "123") { Form2^ form2 = gcnew Form2(); form2->Show(); this->Hide(); } } }; }

    however the output was as follow:

     

    1>e:\vs2010\pass\pass\Form1.h(141): error C2065: 'Form2' : undeclared identifier
    1>e:\vs2010\pass\pass\Form1.h(141): error C2275: 'Pass::form2' : illegal use of this type as an expression
    1>          e:\vs2010\pass\pass\Form2.h(15) : see declaration of 'Pass::form2'
    1>e:\vs2010\pass\pass\Form1.h(141): error C2061: syntax error : identifier 'Form2'
    1>
    1>Build FAILED.
    1>

    notice that i start my code with those syntax:

    #pragma once
    #include "Form2.h"
    namespace Pass {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    Thanks;

     

    Sunday, December 12, 2010 7:00 PM
  • I finally solve this problem, thanks for help anyway

     

    	 {
    					 hello::Form2;
    Form2 ^ dlg = gcnew Form2;
    
      dlg->ShowDialog();
    } 

    • Marked as answer by Shady Enany Friday, December 17, 2010 2:14 AM
    Sunday, December 12, 2010 11:10 PM
  • notice that "hello" is the name of my windows form application, and "Form2" is the name of my new form that i added
    Sunday, December 12, 2010 11:12 PM
  • notice that "hello" is the name of my windows form application, and "Form2" is the name of my new form that i added
    I'm really not sure what is the current state of your code. But if it working now, congratulations!
     

    David Wilkinson | Visual C++ MVP
    Monday, December 13, 2010 1:12 AM