frage wegen Form visual c++ und einer formel für fahrenheit



  • Hallo liebe Freunde von cplusplus Forum 🙂

    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
    {
    // hier möchte ich gerne eine Formel ausgeben z.B. Fahrenheit nach Celsius berechnen
    // fahrenheit = ((celsius * 9) / 5) + 32
    }

    Ich fange gerade mit dem Programmieren an, habe Visual C++ 2005 express edition und baue mir eine Form, ein Formular mit zwei Texteingaben und ein Calculator Button... Jetzt möchte ich das gerne auch umsetzen, aber ich weiß nicht wie ?

    vielleicht kann ja jemand helfen, wäre toll, liebe Grüße, Franziska 🙂

    gesamter code sieht bisher so aus:

    #pragma once

    namespace loulou1 {

    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>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    /// 'Resource File Name' property for the managed resource compiler tool
    /// associated with all .resx files this class depends on. Otherwise,
    /// the designers will not be able to interact properly with localized
    /// resources associated with this form.
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    Form1(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }

    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::Button^ button1;
    private: System::Windows::Forms::Button^ button2;
    private: System::Windows::Forms::TextBox^ textBox1;
    private: System::Windows::Forms::TextBox^ textBox2;
    protected:

    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

    #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
    this->button1 = (gcnew System::Windows::Forms::Button());
    this->button2 = (gcnew System::Windows::Forms::Button());
    this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    this->SuspendLayout();
    //
    // button1
    //
    this->button1->Location = System::Drawing::Point(59, 125);
    this->button1->Name = L"button1";
    this->button1->Size = System::Drawing::Size(154, 78);
    this->button1->TabIndex = 0;
    this->button1->Text = L"say it to me";
    this->button1->UseVisualStyleBackColor = true;
    this->button1->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::button1_MouseClick);
    //
    // button2
    //
    this->button2->Location = System::Drawing::Point(120, 34);
    this->button2->Name = L"button2";
    this->button2->Size = System::Drawing::Size(92, 35);
    this->button2->TabIndex = 1;
    this->button2->Text = L"button2";
    this->button2->UseVisualStyleBackColor = true;
    this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    //
    // textBox1
    //
    this->textBox1->Location = System::Drawing::Point(20, 10);
    this->textBox1->Name = L"textBox1";
    this->textBox1->Size = System::Drawing::Size(55, 20);
    this->textBox1->TabIndex = 2;
    this->textBox1->Click += gcnew System::EventHandler(this, &Form1::textBox1_Click);
    //
    // textBox2
    //
    this->textBox2->Location = System::Drawing::Point(21, 78);
    this->textBox2->Name = L"textBox2";
    this->textBox2->Size = System::Drawing::Size(53, 20);
    this->textBox2->TabIndex = 3;
    this->textBox2->Click += gcnew System::EventHandler(this, &Form1::textBox2_Click);
    //
    // Form1
    //
    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(292, 266);
    this->Controls->Add(this->textBox2);
    this->Controls->Add(this->textBox1);
    this->Controls->Add(this->button2);
    this->Controls->Add(this->button1);
    this->Name = L"Form1";
    this->Text = L"Form1";
    this->ResumeLayout(false);
    this->PerformLayout();

    }
    #pragma endregion
    private: System::Void button1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
    {
    MessageBox::Show("Diese Eingabe ist nicht gültig","Fehler...",MessageBoxButtons::OK,MessageBoxIcon::Information,MessageBoxDefaultButton::Button1,MessageBoxOptions::DefaultDesktopOnly);
    }
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
    {

    }
    private: System::Void textBox1_Click(System::Object^ sender, System::EventArgs^ e)
    {

    }
    private: System::Void textBox2_Click(System::Object^ sender, System::EventArgs^ e)
    {

    }
    };
    }



  • Hehe, okay^^ Sagen wir, du bekommst die Temperatur in °C in der textBox1 und willst dir °F in der textBox2 anzeigen lassen. Das wäre dann so möglich:

    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) 
    { 
       textBox2->Text = (((Convert::ToDouble(textBox1->Text) * 9) / 5.0) + 32).ToString();
    }
    

    MfG 😉



  • super und danke schön, hab's eben ausprobiert und es "funzt" klasse! 😃

    vielen, herzl. Dank auch, bin ganz happy !

    Gilt dieses Muster...

    textBox2->Text = (((Convert::ToDouble(textBox1->Text) * 9) / 5.0) + 32).ToString();

    auch für Formeln oder für Vektor Berechnungen z.B.??

    Gibt es einen guten Link dafür wie ich mit Visual C++ da insgesamt weiter komme? Ich suche schon den ganzen Tag nach Material, uff... muss nicht in englisch sein, besser wäre ein gutes Tutorial in deutsch... 😉

    schönen Abend noch und vielleicht bis bald, habe Appetit bekommen, hamm 🙂

    salute, Franzi



  • Bitte Codetags verwenden.


Anmelden zum Antworten