При запуске оконного приложения C++ в Visual Studio 2019 ничего не происходит
Пробовал изменить подсистему на консоль, ничего не изменилось, при запуске ничего не происходит.
#pragma once
#include "math.h"
namespace Project5 {
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::Button^ button1;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::ComboBox^ comboBox1;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Label^ label5;
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#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->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->label4 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->label5 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(219, 277);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(109, 25);
this->button1->TabIndex = 0;
this->button1->Text = L"Решить";
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(42, 25);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(25, 17);
this->label1->TabIndex = 1;
this->label1->Text = L"X=";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(42, 75);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(25, 17);
this->label2->TabIndex = 2;
this->label2->Text = L"A=";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(42, 126);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(25, 17);
this->label3->TabIndex = 3;
this->label3->Text = L"C=";
//
// comboBox1
//
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Location = System::Drawing::Point(381, 22);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(121, 24);
this->comboBox1->TabIndex = 4;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(282, 22);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(67, 17);
this->label4->TabIndex = 5;
this->label4->Text = L"Функция";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(73, 22);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 22);
this->textBox1->TabIndex = 6;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(73, 72);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 22);
this->textBox2->TabIndex = 7;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(73, 123);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(100, 22);
this->textBox3->TabIndex = 8;
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(36, 167);
this->textBox4->Multiline = true;
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(476, 100);
this->textBox4->TabIndex = 9;
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(381, 96);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(18, 17);
this->checkBox1->TabIndex = 10;
this->checkBox1->UseVisualStyleBackColor = true;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(282, 95);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(33, 17);
this->label5->TabIndex = 11;
this->label5->Text = L"Max";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(542, 314);
this->Controls->Add(this->label5);
this->Controls->Add(this->checkBox1);
this->Controls->Add(this->textBox4);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label4);
this->Controls->Add(this->comboBox1);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
int main()
{
return 0;
};
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
comboBox1->Items->Add("Косинус");
comboBox1->Items->Add("Синус");
comboBox1->Items->Add("Тангенс");
textBox1->Clear();
textBox2->Clear();
textBox3->Clear();
textBox4->Clear();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Double X, A, C, res, MA, y = 0;
X = Convert::ToDouble(textBox1->Text);
A = Convert::ToDouble(textBox2->Text);
C = Convert::ToDouble(textBox3->Text);
switch (comboBox1->SelectedIndex)
{
case 0: res = cos(X); textBox4->Text = String::Format("cos(x) равен {0:F4}", res); break;
case 1: res = sin(X); textBox4->Text = String::Format("sin(x) равен {0:F4}", res); break;
case 2: res = tan(X); textBox4->Text = String::Format("tan(x) равен {0:F4}", res); break;
}
y = pow(sin(res), 2) + A * pow(cos(pow(X, 3)), 5) + C * log(pow(X, 0.4));
textBox4->Text += String::Format("\r\ny = {0:F4}", y) + String::Format("\n при res = {0:F4}", res);
if (X > A) MA = X;
else MA = A;
if (C > MA) MA = C;
if (checkBox1->Checked) {
textBox4->Text = textBox4->Text + Environment::NewLine + String::Format("Max равен {0:F4}", MA);
}
}
};
}
Ответы (1 шт):
Автор решения: Alexander Petrov
→ Ссылка
Удалите из кода метод main.
Если вы создавали проект с помощью готового шаблона, то у вас должен быть файл Program.h со следующим содержимым:
#pragma once
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
ref class Program
{
public:
Program();
[STAThreadAttribute]
static void Main() {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Project5::MyForm());
}
};
Если его нет - создайте.