Erste Form Application und keine Ahnumng



  • Guten Tag
    Im Rahmen unserer Übungsaufgaben sollen wir nun eine gegeben Form Application verändern.
    Bei dem Vorgegeben Programm kann muss man 2 zahlen addieren und innerhalb einer bestimmten Zeit die Lösung in ein Lösungsfeld eingeben.

    1. Änderung: Über eine combobox soll man die zeitdauer wählen können(in 4 stufen).

    Die combobox habe ich auch schon eingefügt aber weiß absolut nicht wie ich diese jetzt codemäßig einbinden soll.

    Kann mir da jemand weiterhelfen, ich bin echt ein absoluter Anfänger auf dem Gebiet.

    Hier mal der code

    namespace Kopfrechnen {
    
    	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::Label^  label1;
    	private: System::Windows::Forms::Label^  label2;
    	private: System::Windows::Forms::Label^  label3;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
    	private: System::Windows::Forms::Button^  button1;
    	private: System::Windows::Forms::ProgressBar^  progressBar1;
    	private: System::Windows::Forms::Timer^  timer1;
    	private: System::ComponentModel::IContainer^  components;
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    
    		Int16 ersterSummand, zweiterSummand; // Summanden der Addition
    		Int16 ergebnis;						 // Egebnis der Addition
    		Int16 minimum, maximum;				 // Grenzen der Addition
    		Random^ autoRand;					 // .NET Version von Random
    	private: System::Windows::Forms::ComboBox^  comboBox1;
    
    	private: System::Windows::Forms::Button^  button2;
    
    	private: 
    		void neueAufgabe() {
    				// Zuerst werden zwei neue Summanden ausgewaehlt
    				Int16 temp = maximum - minimum;
    				ersterSummand = autoRand->Next(temp)+minimum;
    				zweiterSummand = autoRand->Next(temp)+minimum;
    
    				// Das richtige Ergebnis wird zum späteren Vergleich ermittelt
     				ergebnis = ersterSummand+zweiterSummand;
    
    				// Die Zahlen werden in die Textfelder geschrieben
    				this->textBox1->Text = ersterSummand.ToString();
    				this->textBox2->Text = zweiterSummand.ToString();
    
    				// Das Antwortfeld wird "geleert"
    				this->textBox3->Clear();
    
    				// Nun muss die Zeit gestartet und die Progressbar resettet werden
    				this->timer1->Enabled = true;
    				this->progressBar1->Value = this->progressBar1->Minimum;
    		 }
    
    #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->components = (gcnew System::ComponentModel::Container());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
    			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
    			this->label3 = (gcnew System::Windows::Forms::Label());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->button2 = (gcnew System::Windows::Forms::Button());
    			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
    			this->SuspendLayout();
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(38, 36);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(0, 13);
    			this->label1->TabIndex = 0;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Enabled = false;
    			this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->textBox1->Location = System::Drawing::Point(27, 63);
    			this->textBox1->MaxLength = 20;
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(32, 26);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->Text = L"1";
    			this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Location = System::Drawing::Point(65, 71);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(13, 13);
    			this->label2->TabIndex = 2;
    			this->label2->Text = L"+";
    			// 
    			// textBox2
    			// 
    			this->textBox2->AcceptsReturn = true;
    			this->textBox2->Enabled = false;
    			this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->textBox2->Location = System::Drawing::Point(84, 63);
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(32, 26);
    			this->textBox2->TabIndex = 3;
    			this->textBox2->Text = L"1";
    			this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
    


  • sry für den doppelten eintrag, der code war wohl zu lang.
    hier der rest.

    this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(27, 15);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(100, 23);
    			this->button1->TabIndex = 4;
    			this->button1->Text = L"Neue Aufgabe";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// progressBar1
    			// 
    			this->progressBar1->Location = System::Drawing::Point(27, 115);
    			this->progressBar1->Name = L"progressBar1";
    			this->progressBar1->Size = System::Drawing::Size(179, 23);
    			this->progressBar1->Step = 1;
    			this->progressBar1->TabIndex = 5;
    			// 
    			// timer1
    			// 
    			this->timer1->Enabled = true;
    			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
    			// 
    			// label3
    			// 
    			this->label3->AutoSize = true;
    			this->label3->Location = System::Drawing::Point(122, 71);
    			this->label3->Name = L"label3";
    			this->label3->Size = System::Drawing::Size(13, 13);
    			this->label3->TabIndex = 6;
    			this->label3->Text = L"=";
    			// 
    			// textBox3
    			// 
    			this->textBox3->AcceptsReturn = true;
    			this->textBox3->Cursor = System::Windows::Forms::Cursors::IBeam;
    			this->textBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->textBox3->Location = System::Drawing::Point(143, 63);
    			this->textBox3->MaxLength = 5;
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->ShortcutsEnabled = false;
    			this->textBox3->Size = System::Drawing::Size(65, 26);
    			this->textBox3->TabIndex = 7;
    			// 
    			// button2
    			// 
    			this->button2->Cursor = System::Windows::Forms::Cursors::Hand;
    			this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->button2->Location = System::Drawing::Point(143, 15);
    			this->button2->Name = L"button2";
    			this->button2->Size = System::Drawing::Size(62, 23);
    			this->button2->TabIndex = 1;
    			this->button2->Text = L"OK";
    			this->button2->UseVisualStyleBackColor = true;
    			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    			// 
    			// comboBox1
    			// 
    			this->comboBox1->BackColor = System::Drawing::SystemColors::MenuHighlight;
    			this->comboBox1->FormattingEnabled = true;
    			this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(4) {L" 5 sec", L"10 sec", L"15 sec", L"20 sec"});
    			this->comboBox1->Location = System::Drawing::Point(326, 15);
    			this->comboBox1->Name = L"comboBox1";
    			this->comboBox1->Size = System::Drawing::Size(121, 21);
    			this->comboBox1->TabIndex = 8;
    			this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(498, 187);
    			this->Controls->Add(this->comboBox1);
    			this->Controls->Add(this->button2);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->label3);
    			this->Controls->Add(this->progressBar1);
    			this->Controls->Add(this->button1);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->label1);
    			this->Name = L"Form1";
    			this->Text = L"Kopfrechnen";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
    				 // Pro Zeiteinheit (tick) wird die Progressbar um einen Schritt erhoeht
    				 this->progressBar1->PerformStep();
    
    				 // Wenn die Progressbar "am Ende" ist, erscheint eine Meldung
    				 if (this->progressBar1->Value >= this->progressBar1->Maximum) {
    					 // Der Timer muss ZUERST angehalten werden, sonst werden 
    					 // sehr viele weitere Meldungen generiert!
    					 this->timer1->Enabled = false;
    					 MessageBox::Show("Das hat leider zu lange gedauert!","Zeitüberschreitung", MessageBoxButtons::OK, MessageBoxIcon::Hand);
    				 }
    			 }
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    			 // Initialisierung des random seed 
    			 autoRand = gcnew Random;
    
     			 // Grenzen der Addition fuer Laboraufgabe
    			 // als Variablen initialisieren!
    			 minimum = 10; maximum = 50; 
    			 this->neueAufgabe();
    		 }
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    			 // Zahl aus dem Ergebnisfeld holen. Dies fuehrt zu einem Fehler,
    			 // wenn das Ergebnisfeld leer ist (vgl. Uebungsaufgabe!)
    			 Int16 result = Convert::ToInt16(this->textBox3->Text);
    
    			 // Der Timer muss anhalten, weil sonst Zeitueberschreitungsnachrichten
    			 // folgen koennten
    			 this->timer1->Enabled = false;
    
    			 // Nun erfolgt die Ergebnisauswertung
    			 if (result == this->ergebnis) {
    				 MessageBox::Show("Richtig gerechnet!","Information", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
    			 } else {
    				 MessageBox::Show("Leider falsch!","Information", MessageBoxButtons::OK, MessageBoxIcon::Error );
    			 }
    
    			 // Aus aesthetischen Gruenden wird die Progressbar resettet
    			 this->progressBar1->Value = this->progressBar1->Minimum;
    		 }
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    			 this->neueAufgabe();
    		 }
    		 //comboBox für zeitauswahl
    private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
    		 }
    };
    }
    


    1. Das ist WinAPI und gehört ins entsprechende Forum.
    2. Hausaufgaben macht man generell selber, bei konkreten Problemen diese und _den_relevanten_ Code posten


  • nach WINApi sicht das nicht aus



  • also schrieb:

    nach WINApi sicht das nicht aus

    kann auch .NET sein, ist aber 100% kein ISO-C++ => OffTopic



  • das ist vcl



  • otze schrieb:

    das ist vcl

    1. ändert nichts dass es OffTopic ist
    2. steht obe in einem Kommentar was von .NET also wird jenes beteiligt sein und VCL für C++/CLI ost mir nicht bekannt

    btw: VCL ist wenigstens mit Delphi ne super Sache gewesen 🙂



  • stimmt, hast recht. sah nur aufn ersten blick genauso aus...alles halt der selbe müll.



  • Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum C++/CLI mit .NET verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • sry wusste nicht das das in einen anderen topic gehört.

    Ich hab jetzt alle geforderten Änderunge gemacht bis auf folgende:

    ich hab eine comboBox eingebaut in der ich verschiedenen Timerzeiten einstellen können soll

    // comboBox1  ###############ÄNDERUNG
    			// 
    			this->comboBox1->BackColor = System::Drawing::SystemColors::MenuHighlight;
    			this->comboBox1->FormattingEnabled = true;
    			this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(4) {L" 5 sec", L"10 sec", L"15 sec", L"20 sec"});
    			this->comboBox1->Location = System::Drawing::Point(314, 133);
    			this->comboBox1->Name = L"comboBox1";
    			this->comboBox1->Size = System::Drawing::Size(121, 21);
    			this->comboBox1->TabIndex = 8;
    			this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged);
    			//
    

    Mein 1. Problem ich weiß nicht wie ich die 4 eingegebenen werte ({L" 5 sec", L"10 sec", L"15 sec", L"20 sec"});) abfragen kann um dann meine timerzeit zu verändern.

    // timer1
    			// 
    			this->timer1->Enabled = true;
    			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
    

    mein 2. problem: ich weiß überhauptnicht wie ich da eine Timerzeit verändern kann

    vll kann mir jetzt jemand helfen



  • comboBox1->SelectedIndex

    (liefert den aktuellen Index der comboBox zurück...)


Anmelden zum Antworten