A
Endlich fertig gestellt ^^ Ich danke allen, die mir dabei geholfen haben! Ohne euch und insbesondere ohne Shion, hätte ich es wohl nie geschafft.
Der Code sieht nun wie folgt aus:
#pragma once
namespace pytagoras {
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>
/// Zusammenfassung für Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Konstruktorcode hier hinzufügen.
//
}
protected:
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ btnRechnen;
protected:
private: System::Windows::Forms::Button^ btnClear;
private: System::Windows::Forms::TextBox^ txtBox1;
private: System::Windows::Forms::TextBox^ txtBox2;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ txtBox3;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::CheckBox^ chkBox1;
private: System::Windows::Forms::CheckBox^ chkBox2;
private:
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
void InitializeComponent(void)
{
this->btnRechnen = (gcnew System::Windows::Forms::Button());
this->btnClear = (gcnew System::Windows::Forms::Button());
this->txtBox1 = (gcnew System::Windows::Forms::TextBox());
this->txtBox2 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->txtBox3 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->chkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->chkBox2 = (gcnew System::Windows::Forms::CheckBox());
this->SuspendLayout();
//
// btnRechnen
//
this->btnRechnen->Location = System::Drawing::Point(15, 161);
this->btnRechnen->Name = L"btnRechnen";
this->btnRechnen->Size = System::Drawing::Size(75, 23);
this->btnRechnen->TabIndex = 0;
this->btnRechnen->Text = L"Rechnen";
this->btnRechnen->UseVisualStyleBackColor = true;
this->btnRechnen->Click += gcnew System::EventHandler(this, &Form1::btnRechnen_Click);
//
// btnClear
//
this->btnClear->Location = System::Drawing::Point(197, 161);
this->btnClear->Name = L"btnClear";
this->btnClear->Size = System::Drawing::Size(75, 23);
this->btnClear->TabIndex = 1;
this->btnClear->Text = L"Löschen!";
this->btnClear->UseVisualStyleBackColor = true;
this->btnClear->Click += gcnew System::EventHandler(this, &Form1::btnClear_Click);
//
// txtBox1
//
this->txtBox1->Location = System::Drawing::Point(103, 8);
this->txtBox1->Name = L"txtBox1";
this->txtBox1->Size = System::Drawing::Size(75, 20);
this->txtBox1->TabIndex = 3;
//
// txtBox2
//
this->txtBox2->Location = System::Drawing::Point(103, 57);
this->txtBox2->Name = L"txtBox2";
this->txtBox2->Size = System::Drawing::Size(75, 20);
this->txtBox2->TabIndex = 4;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(12, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(57, 17);
this->label1->TabIndex = 5;
this->label1->Text = L"Kathete";
//
// txtBox3
//
this->txtBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->txtBox3->Location = System::Drawing::Point(103, 210);
this->txtBox3->Name = L"txtBox3";
this->txtBox3->Size = System::Drawing::Size(75, 23);
this->txtBox3->TabIndex = 6;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label2->Location = System::Drawing::Point(106, 161);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(72, 20);
this->label2->TabIndex = 7;
this->label2->Text = L"Ergebnis";
//
// chkBox1
//
this->chkBox1->AutoSize = true;
this->chkBox1->Location = System::Drawing::Point(15, 60);
this->chkBox1->Name = L"chkBox1";
this->chkBox1->Size = System::Drawing::Size(72, 17);
this->chkBox1->TabIndex = 8;
this->chkBox1->Text = L"Kathete 2";
this->chkBox1->UseVisualStyleBackColor = true;
//
// chkBox2
//
this->chkBox2->AutoSize = true;
this->chkBox2->Location = System::Drawing::Point(15, 83);
this->chkBox2->Name = L"chkBox2";
this->chkBox2->Size = System::Drawing::Size(89, 17);
this->chkBox2->TabIndex = 9;
this->chkBox2->Text = L"Hypothenuse";
this->chkBox2->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->chkBox2);
this->Controls->Add(this->chkBox1);
this->Controls->Add(this->label2);
this->Controls->Add(this->txtBox3);
this->Controls->Add(this->label1);
this->Controls->Add(this->txtBox2);
this->Controls->Add(this->txtBox1);
this->Controls->Add(this->btnClear);
this->Controls->Add(this->btnRechnen);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void btnRechnen_Click(System::Object^ sender, System::EventArgs^ e)
{
double val1=Convert::ToDouble(txtBox1->Text);
double val2=Convert::ToDouble(txtBox2->Text); //val2 kann hypotenuse oder kathete sein
double val3=0;
if ((chkBox1->Checked && chkBox2->Checked))
{
MessageBox::Show("Bitte für Kathete oder Hypothenuse entscheiden.\r\n Beides zugleich geht nicht!");
}
else if((chkBox1->Checked==false && chkBox2->Checked==false))
{
MessageBox::Show("Bitte wählen Sie die zu berechnende Seite des Dreiecks aus.");
}
else if (chkBox1->Checked)
{
val3=System::Math::Sqrt((val1*val1)+(val2*val2));
}
else if (chkBox2->Checked)
{
if (val2<val1)
{
MessageBox::Show("Der Wert der Hypothenuse muss größer sein, als der Wert der Kathete.\r\nEingabe wiederholen.");
}
else
{
val3=System::Math::Sqrt((val2*val2)-(val1*val1));
}
}
txtBox3->Text=Convert::ToString(val3);
}
private: System::Void btnClear_Click(System::Object^ sender, System::EventArgs^ e)
{
txtBox1->Clear();
txtBox2->Clear();
txtBox3->Clear();
}
};
}
Falls jemand Verbesserungsvorschläge hat, bitte privat an mich schreiben. Der Topic kann somit geschlossen werden.