R
R
Ruslan Tilyaev2021-06-19 19:52:31
.NET
Ruslan Tilyaev, 2021-06-19 19:52:31

Why is windows form not working?

Good day!
Why does the form event not work:

#pragma once

namespace RuslanTilyaev {

  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>
  /// Сводка для MyForm
  /// </summary>
  public ref class MyForm : public System::Windows::Forms::Form
  {
  public:
    MyForm(void)
    {
      InitializeComponent();
      //
      //TODO: добавьте код конструктора
      //
    }

  protected:
    /// <summary>
    /// Освободить все используемые ресурсы.
    /// </summary>
    ~MyForm()
    {
      if (components)
      {
        delete components;
      }
    }
  private: System::Windows::Forms::TextBox^ textBox1;
  private: System::Windows::Forms::TextBox^ textBox2;
  private: System::Windows::Forms::Button^ button1;
  private: System::Windows::Forms::TextBox^ textBox3;
  protected:

  private:
    /// <summary>
    /// Обязательная переменная конструктора.
    /// </summary>
    System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Требуемый метод для поддержки конструктора — не изменяйте 
    /// содержимое этого метода с помощью редактора кода.
    /// </summary>
    void InitializeComponent(void)
    {
      this->textBox1 = (gcnew System::Windows::Forms::TextBox());
      this->textBox2 = (gcnew System::Windows::Forms::TextBox());
      this->button1 = (gcnew System::Windows::Forms::Button());
      this->textBox3 = (gcnew System::Windows::Forms::TextBox());
      this->SuspendLayout();
      // 
      // textBox1
      // 
      this->textBox1->Location = System::Drawing::Point(13, 78);
      this->textBox1->Name = L"textBox1";
      this->textBox1->Size = System::Drawing::Size(100, 20);
      this->textBox1->TabIndex = 0;
      // 
      // textBox2
      // 
      this->textBox2->Location = System::Drawing::Point(160, 78);
      this->textBox2->Name = L"textBox2";
      this->textBox2->Size = System::Drawing::Size(100, 20);
      this->textBox2->TabIndex = 1;
      // 
      // button1
      // 
      this->button1->Location = System::Drawing::Point(106, 124);
      this->button1->Name = L"button1";
      this->button1->Size = System::Drawing::Size(75, 23);
      this->button1->TabIndex = 2;
      this->button1->Text = L"button1";
      this->button1->UseVisualStyleBackColor = true;
      // 
      // textBox3
      // 
      this->textBox3->Location = System::Drawing::Point(28, 179);
      this->textBox3->Name = L"textBox3";
      this->textBox3->Size = System::Drawing::Size(100, 20);
      this->textBox3->TabIndex = 3;
      // 
      // MyForm
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->ClientSize = System::Drawing::Size(284, 261);
      this->Controls->Add(this->textBox3);
      this->Controls->Add(this->button1);
      this->Controls->Add(this->textBox2);
      this->Controls->Add(this->textBox1);
      this->Name = L"Лабараторная работа";
      this->Text = L"Лабараторная работа";
      this->ResumeLayout(false);
      this->PerformLayout();

    }
#pragma endregion
  private: System::Void button1_Click(System::Object^ sender, System::EventArgs^) {
    double a1, b1, res1;
    a1 = Convert::ToDouble(textBox1->Text);
    b1 = Convert::ToDouble(textBox2->Text);
    res1 = a1 + b1;
    textBox3->Text = Convert::ToString(res1);
  }
  };
}

60ce20afd988f341957515.png
Must add the value of the first field with the second and display the result in the third field.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2021-06-19
@Heckfy325

Obviously, because there is no subscription to the click event of button1.
PS. Very strange choice of c++/cli dialect in the presence of c#. You shouldn't do that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question