C++/CLI - how to open a new form and back

后端 未结 3 1631
终归单人心
终归单人心 2021-01-15 16:44

I am creating an application where the front end has to be a Windows Form using C++/CLI. The form is used for login purpose.

In my form, I have a register button. On

3条回答
  •  一向
    一向 (楼主)
    2021-01-15 16:44

    Thereby , I would like to show my full code to help the others:-

    Form2.h

    #pragma once
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    namespace Form1 {
    
    
    
        /// 
        /// Summary for Form2
        /// 
        public ref class Form2 : public System::Windows::Forms::Form
        {
    
    
    
        private: System::Windows::Forms::Form ^ otherform;
        public:
            Form2(System::Windows::Forms::Form ^ o )
            {
                otherform = o;
                InitializeComponent();
    
                //
                //TODO: Add the constructor code here
                //
            }
    
        protected:
            /// 
            /// Clean up any resources being used.
            /// 
            ~Form2()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::Button^  button1;
        protected: 
    
        private:
            /// 
            /// Required designer variable.
            /// 
            System::ComponentModel::Container ^components;
    
            #pragma region Windows Form Designer generated code
            /// 
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// 
            void InitializeComponent(void)
            {
                this->button1 = (gcnew System::Windows::Forms::Button());
                this->SuspendLayout();
                // 
                // button1
                // 
                this->button1->Location = System::Drawing::Point(147, 132);
                this->button1->Name = L"button1";
                this->button1->Size = System::Drawing::Size(102, 38);
                this->button1->TabIndex = 0;
                this->button1->Text = L"Menu";
                this->button1->UseVisualStyleBackColor = true;
                this->button1->Click += gcnew System::EventHandler(this, &Form2::button1_Click);
                // 
                // Form2
                // 
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(412, 295);
                this->Controls->Add(this->button1);
                this->Name = L"Form2";
                this->Text = L"Form2";
                this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
                this->ResumeLayout(false);
    
            }
        #pragma endregion
        private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {
                 }
        private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                     this->Hide();
                 otherform->Show();
    
                 }
        };
    
    
    
    
    
    
        ////////////////////////
    
    }
    

提交回复
热议问题