Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

VC++: value of textBox of form1 have to appear in textBox of form2

$
0
0


Hello,

Sorry if this is a duplicate for some people, but after searching I didn't find an answer that works for me. I need to show what is in textBox1 of Form1 (parent) in textBox2 of Form2 (child). Basically a parent-child communication problem. Please bare with me, I'm new in C++/CLI (VC++ 2008). I've tried to modify [this][1] to do what I need but no luck, I get:

    Used_values.h(30) : warning C4101: 'HERE' : unreferenced local variable
    Used_values.h(560) : error C2065: 'HERE' : undeclared identifier

Here you can find the relevant parts of my code:

Form1 (parent):

    #pragma once
    #include "Used_values.h"

    namespace Vp_vs_gasconcentration_WindowsForm {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;

        public ref class Form1 : public System::Windows::Forms::Form
        {
        public:
            Form1(void)
            {
                InitializeComponent();
            }

        protected:
            ~Form1()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::MenuStrip^  menuStrip1_generalMenu;
        private: System::Windows::Forms::ToolStripMenuItem^  usedValues_ToolStripMenuItem;
        private: System::Windows::Forms::TextBox^  textBox1_waterDepth;
        //(more code...)

        private:
            System::ComponentModel::Container ^components;

    #pragma region Windows Form Designer generated code
            void InitializeComponent(void)
            {
                //(more code...)
                this->textBox1_waterDepth = (gcnew System::Windows::Forms::TextBox());
                //(more code...)
                //
                // textBox1_waterDepth
                //
                this->textBox1_waterDepth->Font = (gcnew System::Drawing::Font(L"Segoe UI", 10));
                this->textBox1_waterDepth->Location = System::Drawing::Point(336, 185);
                this->textBox1_waterDepth->Name = L"textBox1_waterDepth";
                this->textBox1_waterDepth->Size = System::Drawing::Size(100, 25);
                this->textBox1_waterDepth->TabIndex = 1;
                this->textBox1_waterDepth->Text = L"2170";
                this->textBox1_waterDepth->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
                this->textBox1_waterDepth->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_waterDepth_TextChanged);
                //(more code...)
            }

    #pragma endregion
        //(more code...)
        private: System::Void usedValues_ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                     Used_values^ used_values = gcnew Used_values();
                     used_values->StartPosition = FormStartPosition::CenterParent;
                     used_values->ShowDialog();
                     used_values->HERE = textBox1_waterDepth->Text;
                 }
        //(more code...)
    };
    }

Used_values (child):

    #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 Vp_vs_gasconcentration_WindowsForm {

        public ref class Used_values : public System::Windows::Forms::Form
        {
        public:
            Used_values(void)
            {
                InitializeComponent();
                String ^HERE;
            }

        protected:
            ~Used_values()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::TextBox^  textBox1_waterDepthUsedValues;
        //(more code...)

        private:
            System::ComponentModel::Container ^components;

    #pragma region Windows Form Designer generated code
            void InitializeComponent(void)
            {
                //(more code...)
                this->textBox1_waterDepthUsedValues = (gcnew System::Windows::Forms::TextBox());
    (more code...)
                //
                // textBox1_waterDepthUsedValues
                //
                this->textBox1_waterDepthUsedValues->Location = System::Drawing::Point(435, 10);
                this->textBox1_waterDepthUsedValues->Name = L"textBox1_waterDepthUsedValues";
                this->textBox1_waterDepthUsedValues->Size = System::Drawing::Size(100, 25);
                this->textBox1_waterDepthUsedValues->TabIndex = 1;
                this->textBox1_waterDepthUsedValues->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
                this->textBox1_waterDepthUsedValues->TextChanged += gcnew System::EventHandler(this, &Used_values::textBox1_waterDepthUsedValues_TextChanged);
                //(more code...)
            }
    #pragma endregion

    private: System::Void textBox1_waterDepthUsedValues_TextChanged(System::Object^  sender, System::EventArgs^  e) {
                 textBox1_waterDepthUsedValues->Text = HERE;
             }
    };
    }

so, what it should appear in textBox of Form2 (Used_values) is 2170 (default value of textBox in Form1).

Any idea and hint to solve this is very welcome, thanks in advance,


  [1]: http://blog.iandreev.com/?p=194

                                                           

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>