Thread: Read contents of textbox as string and pass it to another textbox as string

  1. #1
    Registered User topten2016's Avatar
    Join Date
    Feb 2016
    Posts
    17

    Read contents of textbox as string and pass it to another textbox as string

    Hello
    I have created a winform with 2 textboxes. I need to read the data from first textbox as a string and then pass this data to another textbox as a string. How can I do it?

    Here is the code of .h file

    Code:
    #pragma once
    
    
    namespace Forma {
    
        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;
    
        /// <summary>
        /// 
        /// </summary>
        public ref class MyForm : public System::Windows::Forms::Form
        {
        public:
            MyForm(void)
            {
                InitializeComponent();
                //
                
                //
            }
    
        protected:
            /// <summary>
            ///
            /// </summary>
            ~MyForm()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::Button^  button1;
        private: System::Windows::Forms::Label^  label1;
        private: System::Windows::Forms::TextBox^  num1;
        private: System::Windows::Forms::TextBox^  num2;
    
    
        private: System::Windows::Forms::Label^  label2;
        private: System::Windows::Forms::Label^  label3;
    
    
    
    
        private: System::ComponentModel::IContainer^  components;
        protected:
    
        private:
            /// <summary>
            /// 
            /// </summary>
    
    
    #pragma region Windows Form Designer generated code
            /// <summary>
            
            /// </summary>
            void InitializeComponent(void)
            {
                this->button1 = (gcnew System::Windows::Forms::Button());
                this->label1 = (gcnew System::Windows::Forms::Label());
                this->num1 = (gcnew System::Windows::Forms::TextBox());
                this->num2 = (gcnew System::Windows::Forms::TextBox());
                this->label2 = (gcnew System::Windows::Forms::Label());
                this->label3 = (gcnew System::Windows::Forms::Label());
                this->SuspendLayout();
                // 
                // button1
                // 
                this->button1->Location = System::Drawing::Point(101, 216);
                this->button1->Name = L"button1";
                this->button1->Size = System::Drawing::Size(107, 41);
                this->button1->TabIndex = 0;
                this->button1->Text = L"start";
                this->button1->UseVisualStyleBackColor = true;
                this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
                // 
                // label1
                // 
                this->label1->AutoSize = true;
                this->label1->Location = System::Drawing::Point(98, 9);
                this->label1->Name = L"label1";
                this->label1->Size = System::Drawing::Size(81, 13);
                this->label1->TabIndex = 1;
                this->label1->Text = L"Simple Example";
                this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
                // 
                // num1
                // 
                this->num1->Location = System::Drawing::Point(101, 68);
                this->num1->Name = L"num1";
                this->num1->Size = System::Drawing::Size(141, 20);
                this->num1->TabIndex = 2;
                this->num1->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox1_TextChanged);
                // 
                // num2
                // 
                this->num2->Location = System::Drawing::Point(65, 130);
                this->num2->Name = L"num2";
                this->num2->Size = System::Drawing::Size(177, 20);
                this->num2->TabIndex = 3;
                // 
                // label2
                // 
                this->label2->AutoSize = true;
                this->label2->Location = System::Drawing::Point(22, 71);
                this->label2->Name = L"label2";
                this->label2->Size = System::Drawing::Size(54, 13);
                this->label2->TabIndex = 4;
                this->label2->Text = L"input data";
                // 
                // label3
                // 
                this->label3->AutoSize = true;
                this->label3->Location = System::Drawing::Point(22, 133);
                this->label3->Name = L"label3";
                this->label3->Size = System::Drawing::Size(41, 13);
                this->label3->TabIndex = 5;
                this->label3->Text = L"answer";
                // 
                // MyForm
                // 
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(311, 284);
                this->Controls->Add(this->label3);
                this->Controls->Add(this->label2);
                this->Controls->Add(this->num2);
                this->Controls->Add(this->num1);
                this->Controls->Add(this->label1);
                this->Controls->Add(this->button1);
                this->MaximizeBox = false;
                this->Name = L"MyForm";
                this->Text = L"Myform";
                this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
                this->ResumeLayout(false);
                this->PerformLayout();
    
            }
    #pragma endregion
        private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        
    
        }
        private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
        }
        private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
        }
        private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
        }
        };
    }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by topten2016 View Post
    Hello
    I have created a winform with 2 textboxes. I need to read the data from first textbox as a string and then pass this data to another textbox as a string. How can I do it?
    First of all, you use C++/CLI, not C++.
    Just do a simple assignment:


    Code:
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
        num1->Text = num2->Text;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-14-2012, 11:58 PM
  2. Textbox to string
    By Coding in forum C++ Programming
    Replies: 25
    Last Post: 02-02-2008, 08:14 PM
  3. Textbox
    By maxorator in forum Windows Programming
    Replies: 20
    Last Post: 09-25-2005, 10:04 AM
  4. how read line by line from textbox
    By lostai in forum Windows Programming
    Replies: 1
    Last Post: 02-14-2003, 08:47 AM
  5. Replies: 1
    Last Post: 07-24-2002, 06:33 AM