tabs per knopfdruck



  • Hi Leute
    Ich nutze Visual c++.
    Meine Frage:

    Ich habe zwei Forms in dem einen ist ein button in dem anderen ein paar tabs.Jetzt möchte ich wenn man den button drückt, das sich automatisch ein neues Tab im ersten Form dazu "gesellt".

    Hat da einer ne idee?



  • heino schrieb:

    Hi Leute
    Ich nutze Visual c++.
    Meine Frage:

    Ich habe zwei Forms in dem einen ist ein button in dem anderen ein paar tabs.Jetzt möchte ich wenn man den button drückt, das sich automatisch ein neues Tab im ersten Form dazu "gesellt".

    Hat da einer ne idee?

    Keiner eine Idee??



  • So hier ist mal der Code:

    Das HauptForm:

    #pragma once
    
    #include "Form2.h"
    
    namespace training {
    
    	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
    	///
    	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
    	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
    	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
    	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
    	///          arbeiten, die diesem Formular zugewiesen sind.
    	/// </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::MenuStrip^  menuStrip1;
    
    	protected: 
    	private: System::Windows::Forms::ToolStripMenuItem^  dateiToolStripMenuItem;
    	private: System::Windows::Forms::ToolStripMenuItem^  bearbeitenToolStripMenuItem;
    	private: System::Windows::Forms::ToolStripMenuItem^  kateiHinzufügenToolStripMenuItem;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TabPage^  tabPage2;
    	private: System::Windows::Forms::TabPage^  tabPage1;
    	private: System::Windows::Forms::TabControl^  tabControl1;
    	private: System::Windows::Forms::TabPage^  tabPage3;
    	private: System::Windows::Forms::TabPage^  tabPage4;
    	private: System::Windows::Forms::TabPage^  tabPage5;
    
    	private: System::ComponentModel::IContainer^  components;
    
    	private:
    		/// <summary>
    		/// Erforderliche Designervariable.
    		/// </summary>
    
    #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>
    
    	public:
    		void InitializeComponent(void)
    		{
    			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
    			this->dateiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->bearbeitenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->kateiHinzufügenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
    			this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
    			this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
    			this->tabPage3 = (gcnew System::Windows::Forms::TabPage());
    			this->tabPage4 = (gcnew System::Windows::Forms::TabPage());
    			this->tabPage5 = (gcnew System::Windows::Forms::TabPage());
    			this->menuStrip1->SuspendLayout();
    			this->tabControl1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// menuStrip1
    			// 
    			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->dateiToolStripMenuItem, 
    				this->bearbeitenToolStripMenuItem});
    			this->menuStrip1->Location = System::Drawing::Point(0, 0);
    			this->menuStrip1->Name = L"menuStrip1";
    			this->menuStrip1->RenderMode = System::Windows::Forms::ToolStripRenderMode::System;
    			this->menuStrip1->Size = System::Drawing::Size(989, 24);
    			this->menuStrip1->TabIndex = 0;
    			this->menuStrip1->Text = L"menuStrip1";
    			this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::menuStrip1_ItemClicked);
    			// 
    			// dateiToolStripMenuItem
    			// 
    			this->dateiToolStripMenuItem->Name = L"dateiToolStripMenuItem";
    			this->dateiToolStripMenuItem->Size = System::Drawing::Size(44, 20);
    			this->dateiToolStripMenuItem->Text = L"Datei";
    			// 
    			// bearbeitenToolStripMenuItem
    			// 
    			this->bearbeitenToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->kateiHinzufügenToolStripMenuItem});
    			this->bearbeitenToolStripMenuItem->Name = L"bearbeitenToolStripMenuItem";
    			this->bearbeitenToolStripMenuItem->Size = System::Drawing::Size(70, 20);
    			this->bearbeitenToolStripMenuItem->Text = L"Bearbeiten";
    			// 
    			// kateiHinzufügenToolStripMenuItem
    			// 
    			this->kateiHinzufügenToolStripMenuItem->Name = L"kateiHinzufügenToolStripMenuItem";
    			this->kateiHinzufügenToolStripMenuItem->Size = System::Drawing::Size(155, 22);
    			this->kateiHinzufügenToolStripMenuItem->Text = L"Katei Hinzufügen";
    			this->kateiHinzufügenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::kateiHinzufügenToolStripMenuItem_Click);
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(73, 69);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(100, 20);
    			this->textBox1->TabIndex = 0;
    			// 
    			// tabControl1
    			// 
    			this->tabControl1->Controls->Add(this->tabPage1);
    			this->tabControl1->Controls->Add(this->tabPage2);
    			this->tabControl1->Controls->Add(this->tabPage3);
    			this->tabControl1->Controls->Add(this->tabPage4);
    			this->tabControl1->Controls->Add(this->tabPage5);
    			this->tabControl1->Location = System::Drawing::Point(2, 211);
    			this->tabControl1->Name = L"tabControl1";
    			this->tabControl1->Padding = System::Drawing::Point(7, 3);
    			this->tabControl1->SelectedIndex = 0;
    			this->tabControl1->Size = System::Drawing::Size(986, 339);
    			this->tabControl1->TabIndex = 1;
    			// 
    			// tabPage1
    			// 
    			this->tabPage1->Location = System::Drawing::Point(4, 22);
    			this->tabPage1->Name = L"tabPage1";
    			this->tabPage1->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage1->Size = System::Drawing::Size(978, 313);
    			this->tabPage1->TabIndex = 0;
    			this->tabPage1->Text = L"Bankdrücken";
    			this->tabPage1->UseVisualStyleBackColor = true;
    			this->tabPage1->Click += gcnew System::EventHandler(this, &Form1::tabPage1_Click);
    			// 
    			// tabPage2
    			// 
    			this->tabPage2->Location = System::Drawing::Point(4, 22);
    			this->tabPage2->Name = L"tabPage2";
    			this->tabPage2->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage2->Size = System::Drawing::Size(978, 313);
    			this->tabPage2->TabIndex = 1;
    			this->tabPage2->Text = L"Biceps";
    			this->tabPage2->UseVisualStyleBackColor = true;
    			this->tabPage2->Click += gcnew System::EventHandler(this, &Form1::tabPage2_Click);
    			// 
    			// tabPage3
    			// 
    			this->tabPage3->Location = System::Drawing::Point(4, 22);
    			this->tabPage3->Name = L"tabPage3";
    			this->tabPage3->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage3->Size = System::Drawing::Size(978, 313);
    			this->tabPage3->TabIndex = 2;
    			this->tabPage3->Text = L"tabPage3";
    			this->tabPage3->UseVisualStyleBackColor = true;
    			// 
    			// tabPage4
    			// 
    			this->tabPage4->Location = System::Drawing::Point(4, 22);
    			this->tabPage4->Name = L"tabPage4";
    			this->tabPage4->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage4->Size = System::Drawing::Size(978, 313);
    			this->tabPage4->TabIndex = 3;
    			this->tabPage4->Text = L"tabPage4";
    			this->tabPage4->UseVisualStyleBackColor = true;
    			// 
    			// tabPage5
    			// 
    			this->tabPage5->Location = System::Drawing::Point(4, 22);
    			this->tabPage5->Name = L"tabPage5";
    			this->tabPage5->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage5->Size = System::Drawing::Size(978, 313);
    			this->tabPage5->TabIndex = 4;
    			this->tabPage5->Text = L"tabPage5";
    			this->tabPage5->UseVisualStyleBackColor = true;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(989, 553);
    			this->Controls->Add(this->tabControl1);
    			this->Controls->Add(this->menuStrip1);
    			this->MainMenuStrip = this->menuStrip1;
    			this->Name = L"Form1";
    			this->Text = L"Training";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->menuStrip1->ResumeLayout(false);
    			this->menuStrip1->PerformLayout();
    			this->tabControl1->ResumeLayout(false);
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    private:
    #pragma endregion
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    			 }
    	private: System::Void kateiHinzufügenToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
    	            /* Form2 ^frm2 = gcnew Form2();
    	             frm2->ShowDialog(this);*/
    
    		 }
    
    private: System::Void tabPage2_Click(System::Object^  sender, System::EventArgs^  e) {
    		 }
    private: System::Void tabPage1_Click(System::Object^  sender, System::EventArgs^  e) {
    		 }
    private: System::Void menuStrip1_ItemClicked(System::Object^  sender, System::Windows::Forms::ToolStripItemClickedEventArgs^  e) {
    		 }
    
    };
    }
    

    Hier das Zweite Form:

    #pragma once
    
    #include "Form1.h"
    
    namespace training {
    
    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 Form2
    	///
    	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
    	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
    	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
    	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
    	///          arbeiten, die diesem Formular zugewiesen sind.
    	/// </summary>
    	public ref class Form2 : public System::Windows::Forms::Form
    	{
    	public:
    		Form2(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Konstruktorcode hier hinzufügen.
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Verwendete Ressourcen bereinigen.
    		/// </summary>
    		~Form2()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Label^  label1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::Button^  button1;
    	private: System::Windows::Forms::Button^  button2;
    	private: System::Windows::Forms::TabControl^ tabControl1;// zum test
    	private: System::Windows::Forms::TabPage^  tabPage1;//zum test
    
    	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->label1 = (gcnew System::Windows::Forms::Label());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->button2 = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(80, 9);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(225, 13);
    			this->label1->TabIndex = 0;
    			this->label1->Text = L"Bitte geben sie einen Namen für die Kartei ein:";
    			this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(83, 42);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(221, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->Text = L"ddd";
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(219, 114);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(72, 22);
    			this->button1->TabIndex = 2;
    			this->button1->Text = L"OK";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form2::button1_Click);
    			// 
    			// button2
    			// 
    			this->button2->Location = System::Drawing::Point(311, 114);
    			this->button2->Name = L"button2";
    			this->button2->Size = System::Drawing::Size(77, 21);
    			this->button2->TabIndex = 3;
    			this->button2->Text = L"Cancel";
    			this->button2->UseVisualStyleBackColor = true;
    			// 
    			// Form2
    			// 
    			this->AcceptButton = this->button1;
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(407, 153);
    			this->Controls->Add(this->button2);
    			this->Controls->Add(this->button1);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->label1);
    			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
    			this->Name = L"Form2";
    			this->Text = L"Kartei Hinzufügen";
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    
    			 }
    	};
    }
    

    So wie bekomme ich es jetzt hin bei

    public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    
    			 }
    

    einen Eintrag zumachen das er ein Tab im HauptForm anfügt?



  • // 
                // tabControl1 
                // 
                this->tabControl1->Controls->Add(this->tabPage1); 
                this->tabControl1->Controls->Add(this->tabPage2); 
                this->tabControl1->Controls->Add(this->tabPage3); 
                this->tabControl1->Controls->Add(this->tabPage4); 
                this->tabControl1->Controls->Add(this->tabPage5); 
                this->tabControl1->Location = System::Drawing::Point(2, 211); 
                this->tabControl1->Name = L"tabControl1"; 
                this->tabControl1->Padding = System::Drawing::Point(7, 3); 
                this->tabControl1->SelectedIndex = 0; 
                this->tabControl1->Size = System::Drawing::Size(986, 339); 
                this->tabControl1->TabIndex = 1;
    

    Was gibts da jetzt nich zu verstehen ? Schau Dir den Initcode an, da bekommst gezeigt wie das geht



  • ja das ist ja auch kein problem.Das Problem ist das ich es im Form2 klicke und in Form1 eingefügt werden soll.



  • Naja, dann füge es doch auch auf Form1 hinzu ^^



  • Knuddlbaer schrieb:

    Naja, dann füge es doch auch auf Form1 hinzu ^^

    Nee ich glaub du verstehst da was falsch.Mal GANZ einfach.Ich möchte etwas per knopfdruck (Form2) auf Form1 übertragen.SO mein ich das.

    Das ein neues Tab geöffnet wird schaffe ich ja nur halt auf dem selben Form(form2) wo ich auch den Button drücke.Das will ich aber nicht sondern das soll auf Form1 übertragen werden.



  • Naja, WO ist denn dabei DEIN Problem ?



  • Knuddlbaer schrieb:

    Naja, WO ist denn dabei DEIN Problem ?

    Es auf Form1 darzustellen.



  • Sorry, so ganz versteh ich dich auch nicht...

    Du willst von einer Form was in die andere übernehmen? Bei einer SDI Anwendung?
    Dann brauchst du doch nur z.B. Form2 in Form1 einbinden, eine neue Instanz von Form2 erstellen und diese mit ShowDialog() aufrufen... Wenn du jetzt Werte, oder was weiss ich, von einer Form zur anderen übergeben willst, nutzt du ein property oder eine Methode...



  • Dappeljuh schrieb:

    Sorry, so ganz versteh ich dich auch nicht...

    Du willst von einer Form was in die andere übernehmen? Bei einer SDI Anwendung?
    Dann brauchst du doch nur z.B. Form2 in Form1 einbinden, eine neue Instanz von Form2 erstellen und diese mit ShowDialog() aufrufen... Wenn du jetzt Werte, oder was weiss ich, von einer Form zur anderen übergeben willst, nutzt du ein property oder eine Methode...

    GENAU.Form2 hab ich ja schon damit eingebunden:

    Form2 ^frm2 = gcnew Form2();
                     frm2->ShowDialog(this);
    

    Wie schreib ich jetzt ein property oder eine Methode?



  • Du weisst nicht wie man eine Methode erstellt??

    private: bool meineMethode(bool argA)
    {
        if(argA)
        {
            //mach irgendwas...
            return true;
        }
        else
        {
            //mach irgendwas anderes
        }
        return false;
    }
    

    Wenn du da noch Probleme hast, schau dir noch mal die Grundlagen an...
    Sonst wirst du nicht weit kommen.

    property´s sind in der FAQ beschrieben...



  • Dappeljuh schrieb:

    Du weisst nicht wie man eine Methode erstellt??

    private: bool meineMethode(bool argA)
    {
        if(argA)
        {
            //mach irgendwas...
            return true;
        }
        else
        {
            //mach irgendwas anderes
        }
        return false;
    }
    

    Wenn du da noch Probleme hast, schau dir noch mal die Grundlagen an...
    Sonst wirst du nicht weit kommen.

    property´s sind in der FAQ beschrieben...

    Den einen Teil hab ich ja schon ^^

    public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    
                 }
    


  • Das ist der Eventhandler!

    Schau dir ersteinmal die property´s an!
    Mit denen kannst du dann doch alles hin und herschicken...



  • Boahr ich verzweifel noch.Ich bin zu blöd dafür.Kann mir nicht einer das mal so schreiben wie ich es brauch??Bitte

    Der komplette Code steht auf der ersten Seite.



  • Ist dieser Eintrag noch aktuel?

    Wenn ja:

    [cpp]
    public: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    TabControl^ tabC = gcnew TabControl();
    tabC->TabPage->Add("Text der TabPage");
    Form1->Controls->Add(tabC);

    }


Anmelden zum Antworten