none
Anfänger Problem zur Erstellung einer Berechnung in Visual Studio 2011 RRS feed

  • Frage

  • Hallo liebe Profis,

    bevor ich anfange,  ich weiß man kann sich auch das Buch kaufen und alle seiten durchlesen um schlauer zu sein oder " wie kann man nur ohne Ahnung sowas überhaupt probieren"  - dessen bin ich mir Bewust. Danke

    Also:  ich brauche nur ein feld bei mir auf dem Desktop - was mir eine simple rechung ausführt.

    Feld a =  zahl

    +

    Feld b = zahl

    =

    feld c = ergebnis

     

    #pragma once
    
    namespace My16 {
    
    	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::TextBox^  textBox1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
    
    	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->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(185, 56);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(100, 20);
    			this->textBox1->TabIndex = 0;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(185, 146);
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(100, 20);
    			this->textBox2->TabIndex = 1;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(185, 242);
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(100, 20);
    			this->textBox3->TabIndex = 2;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->BackColor = System::Drawing::SystemColors::ActiveCaption;
    			this->ClientSize = System::Drawing::Size(677, 550);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    			 }
    	};
    }
    


    weiter komme ich leider nicht . 

    ist eine Textbox überhaupt richtig ? oder eine Richtextbox ?  

     

    Ich wäre über hilfe wirklich dankbar.

     

    danke Guido

    Samstag, 14. Januar 2012 13:26

Antworten

  • Hallo Guido,

    vorab: Wenn es _das_ Buch gäbe, hätten wir das alle^^ Und Fragen zu stellen, bevor man alles weiß, ist der Sinn und Zweck des Forums. Andersrum wären wir alle arbeitslos :)

    Die Frage wäre im C++ Forum besser aufgehoben, da es ja um programmierspezifische Fragen und nicht um allgemeine Frage zu Visual Studio geht. Ein Moderator kann den Beitrag sicher verschieben.

    Ich hab von C++ keine Ahnung, daher schreibe ich nur mal die allgemeine Vorgehensweise:

    Eine TextBox hat die Eigenschaft Text. Diese stellt einen String dar. Mit einem string kann man aber nicht rechnen. Daher musst Du deine Werte für die Berechnung noch konvertieren. Um den Wert dann wieder auszugeben, bspw. in ein Label Control, muss das Ergebnis dann wieder in einen String gewandelt werden. Ich probier mal, den Code zusammenzubasteln aber wie gesagt, C++ und meine Wenigkeit werden keine Freunde^^, daher kann/wird der Code Fehler enthalten.

     

    private: System::Void textBox1_TextChanged( System::Object^  sender, System::EventArgs^  e )
    {
    System::Int64 Value1 = (Int64)textBox1->Text;
    System::Int64 Value2 = (Int64)textBox2->Text;
    System::Int64 Result = Value1 + Value2;
    
        label1->Text = Result->ToString();
    }
    
    

     


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Samstag, 14. Januar 2012 13:57
    Moderator

Alle Antworten