Child-Window



  • Hallo,

    Ich möchte eine Windows-Forms-Anwendung erstellen und zwar mit MDI.
    Ich bin soweit, dass ich ein parent und ein child habe, was auch funktioniert, aber wie rufe ich ein weiteres child über das erste child auf? Also ich klicke auf einen Button und da soll das aktuelle Child-Form zugehen (funktioniert) und ein neues Child-Form aufgehen. Mir fällt dazu einfach nichts mehr ein, hab alles Mögliche ausprobiert, gelesen... es funktioniert einfach nicht.

    Danke schon mal.



  • es funktioniert einfach nicht.

    Das ist aber keine Beschreibung des Problems ^^

    Ein zweites Child legst Du genauso an wie das erste. Instanz erzeugen, MDI Parent eingtragen und Show aufrufen.



  • Hm, dass das wie bei dem ersten funktionieren sollte, ist mir schon klar, aber so geht es nicht - er findet beim zweiten das Parent nicht.

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    {
    	 Close();
    	 anmelden->MdiChildren =  ??? 
    	 anmelden->Show();
    }
    


  • Die Informationen sind ein wenig Mager.
    Ich nehme an, das Dein Beispielcode aus einem MDI Child kommt und Du das zweite Childfenster
    im gleichen Parent anzeigen willst. (Dein Quellcode ergibt mit Deinem Post zusammen keinen Sinn.)

    Ich rate mal:

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
    {
         anmelden->MdiParent =  this->MdiParent;
         anmelden->Show();
         Close();
    }
    


  • Du hast richtig geraten. Wenn ich das so mache, wie du geschrieben hast, kommt folgende Fehlermeldung:

    Error 1 error C2039: 'set' : is not a member of 'System::Windows::Forms::Form::MdiChildren'



  • Halt! Falsch, hatte was falsch gemacht. Aber es funktioniert trotzdem nicht. Das neue Fenster ist trotzdem kein Childfenster. Kommt zwar keine Fehlermeldung, aber es tauchen wieder 2 Fenster auf der Taskleiste auf und ich kann es aus dem Parent rausziehen.



  • Poste mal den konkreten Quellcode und erläutere, von welchem Element dieser kommt. Das Rätselraten mag ich nicht und führt auch zu nichts.

    tauchen wieder 2 Fenster auf der Taskleiste auf und ich kann es aus dem Parent rausziehen.

    Ist das Hauptfenster überhaupt ein MDIContainer Fenster ?



  • Das Hauptfenster ist ein MDI-Container, sonst würde das erste Childfenster ja auch nicht funktionieren.

    Hauptfenster:

    #pragma once
    #include "Start.h"
    
    namespace Kundenverwaltung {
    
    	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
    	{
    		Start ^anfang; //Instanzvariable für Start.h
    
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    			anfang = gcnew Start();	
    
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    
    	private: System::Windows::Forms::MenuStrip^  menuStrip1;
    	protected: 
    	private: System::Windows::Forms::ToolStripMenuItem^  beendenToolStripMenuItem;
    
    	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->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
    			this->beendenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->menuStrip1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// menuStrip1
    			// 
    			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->beendenToolStripMenuItem});
    			this->menuStrip1->Location = System::Drawing::Point(0, 0);
    			this->menuStrip1->Name = L"menuStrip1";
    			this->menuStrip1->Size = System::Drawing::Size(989, 24);
    			this->menuStrip1->TabIndex = 0;
    			this->menuStrip1->Text = L"menuStrip1";
    			// 
    			// beendenToolStripMenuItem
    			// 
    			this->beendenToolStripMenuItem->Name = L"beendenToolStripMenuItem";
    			this->beendenToolStripMenuItem->Size = System::Drawing::Size(65, 20);
    			this->beendenToolStripMenuItem->Text = L"&Beenden";
    			this->beendenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::beendenToolStripMenuItem_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(989, 718);
    			this->Controls->Add(this->menuStrip1);
    			this->IsMdiContainer = true;
    			this->MainMenuStrip = this->menuStrip1;
    			this->Name = L"Form1";
    			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
    			this->Text = L"YS-Soft Kundenverwaltung 5.0 für Windows";
    			this->Shown += gcnew System::EventHandler(this, &Form1::Form1_Shown);
    			this->menuStrip1->ResumeLayout(false);
    			this->menuStrip1->PerformLayout();
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	private: System::Void beendenToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
    				 Close();
    			 }
    
    	private: System::Void Form1_Shown(System::Object^  sender, System::EventArgs^  e) {
    				 anfang->MdiParent = this;
    				 anfang->Show(); //zeigt Start.h als nicht-modalen Dialog
    			 }
    
    	};
    }
    

    1. Child:

    #pragma once
    #include "Login.h"
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    namespace Kundenverwaltung {
    
    	/// <summary>
    	/// Summary for Start
    	///
    	/// 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 Start : public System::Windows::Forms::Form
    	{
    			Login ^anmelden;	
    	public:
    		Start(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    			anmelden = gcnew Login();
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Start()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	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)
    		{
    			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Start::typeid));
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"button1.Image")));
    			this->button1->Location = System::Drawing::Point(27, 58);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(633, 285);
    			this->button1->TabIndex = 0;
    			this->button1->TextImageRelation = System::Windows::Forms::TextImageRelation::ImageAboveText;
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Start::button1_Click);
    			// 
    			// Start
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(686, 400);
    			this->Controls->Add(this->button1);
    			this->Name = L"Start";
    			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
    			this->Text = L"Kundenverwaltung 5.0";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    				 Close();
    				 anmelden->MdiParent = this->MdiParent;
    				 anmelden->Show();
    			}
    	};
    }
    

    2. Child:

    #pragma once
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    namespace Kundenverwaltung {
    
    	/// <summary>
    	/// Summary for Login
    	///
    	/// 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 Login : public System::Windows::Forms::Form
    	{
    	public:
    		Login(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Login()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::Label^  label2;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    
    	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->label1 = (gcnew System::Windows::Forms::Label());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->button1->Location = System::Drawing::Point(552, 335);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(98, 39);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"OK";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->label1->Location = System::Drawing::Point(88, 120);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(127, 24);
    			this->label1->TabIndex = 1;
    			this->label1->Text = L"Nutzer-Name:";
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->label2->Location = System::Drawing::Point(91, 170);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(90, 24);
    			this->label2->TabIndex = 2;
    			this->label2->Text = L"Passwort:";
    			// 
    			// textBox1
    			// 
    			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(260, 118);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(246, 26);
    			this->textBox1->TabIndex = 3;
    			// 
    			// textBox2
    			// 
    			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(260, 168);
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->PasswordChar = '*';
    			this->textBox2->Size = System::Drawing::Size(246, 26);
    			this->textBox2->TabIndex = 4;
    			// 
    			// Login
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(686, 400);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Login";
    			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
    			this->Text = L"Login";
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	};
    }
    


  • Ein geschlossenes Fenster hat keinen MdiParent.
    Erst nachdem du den Zeiger kopiert hast, darfst du das erste
    Fenster schließen. (also die ersten zwei Zeilen in der button1-Methode
    vertauschen)

    Alex



  • Knuddlbaer schrieb:

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
    {
         anmelden->MdiParent =  this->MdiParent;
         anmelden->Show();
         Close();
    }
    


  • Vielen Dank! Es funktioniert 😃


Anmelden zum Antworten