Hello! Please tell me how to correctly transfer from the input field the text that was entered by the user in the text output field above?

This is what the interface model looks like.

program form model

For the input field I used Rich TextBox and half a button clicking. Say the text should be formatted with my code and get into the text output field. I used List View as the output of the entered text.

The text should be displayed without erasing the previous text. The old text is scrolled automatically up or down, and the new text (which was re-entered into the input field) is displayed on the screen.

How correctly to receive the text from the input field without errors, to format it with my code and then output such text in the output field?

here is the source code

#pragma once namespace form { 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> /// Сводка для Form1 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: добавьте код конструктора // } protected: /// <summary> /// Освободить все используемые ресурсы. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::ListView^ listView1; protected: private: System::Windows::Forms::PictureBox^ pictureBox1; private: System::Windows::Forms::RichTextBox^ richTextBox1; private: System::Windows::Forms::Button^ button1; private: /// <summary> /// Требуется переменная конструктора. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Обязательный метод для поддержки конструктора - не изменяйте /// содержимое данного метода при помощи редактора кода. /// </summary> void InitializeComponent(void) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->listView1 = (gcnew System::Windows::Forms::ListView()); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox()); this->button1 = (gcnew System::Windows::Forms::Button()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit(); this->SuspendLayout(); // // listView1 // this->listView1->Location = System::Drawing::Point(201, -1); this->listView1->Name = L"listView1"; this->listView1->Size = System::Drawing::Size(417, 309); this->listView1->TabIndex = 0; this->listView1->UseCompatibleStateImageBehavior = false; // // pictureBox1 // this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image"))); this->pictureBox1->Location = System::Drawing::Point(-2, -1); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->Size = System::Drawing::Size(197, 448); this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage; this->pictureBox1->TabIndex = 1; this->pictureBox1->TabStop = false; // // richTextBox1 // this->richTextBox1->Location = System::Drawing::Point(201, 314); this->richTextBox1->Name = L"richTextBox1"; this->richTextBox1->Size = System::Drawing::Size(417, 99); this->richTextBox1->TabIndex = 2; this->richTextBox1->Text = L""; // // button1 // this->button1->Location = System::Drawing::Point(201, 420); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(417, 23); this->button1->TabIndex = 3; this->button1->Text = L"Сказать"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(622, 447); this->Controls->Add(this->button1); this->Controls->Add(this->richTextBox1); this->Controls->Add(this->pictureBox1); this->Controls->Add(this->listView1); this->MaximizeBox = false; this->Name = L"Form1"; this->Text = L"Form1"; (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit(); this->ResumeLayout(false); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { } }; } 

    1 answer 1

    You need a ListView.Items.Add method

    You need to pass it the value from the textbox:

     this->listView1.Add(this->richTextBox1->Text); 
    • ATP, for a hint, but apparently I do not quite understand the structure of the form. How to get text from a rich textbox when clicking a mouse? and send it in List View. Set an example if not difficult. private: System :: void button1_Click (System :: Object ^ sender, System :: EventArgs ^ e) {this-> listView1.Add (this-> richTextBox1-> Text);}} - Anton
    • @ Anton, but what’s the structure of the form? - Grundy
    • I apologize, in the sense of not understanding how to use the functions of the forms - Anton
    • @ Anton, consider the form as an ordinary class, controls on the form - these are fields of this class - and everything becomes clear, as it seems to me - Grundy