#pragma once


namespace CreateGraphics {

	using namespace System;
	using namespace System::ComponentModel;
   using namespace System::Collections::Generic;
	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
	{
   private:
      List<Point>^ koordinaten;

	public:
		Form1(void)
		{
			InitializeComponent();

         koordinaten = gcnew List<Point>();
		}

	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
   private: System::Windows::Forms::Label^  label1;
   protected: 
   private: System::Windows::Forms::Panel^  panel1;

	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->panel1 = (gcnew System::Windows::Forms::Panel());
         this->SuspendLayout();
         // 
         // label1
         // 
         this->label1->Dock = System::Windows::Forms::DockStyle::Top;
         this->label1->Location = System::Drawing::Point(10, 10);
         this->label1->Name = L"label1";
         this->label1->Size = System::Drawing::Size(434, 49);
         this->label1->TabIndex = 0;
         this->label1->Text = L"Zeichnen Sie mit gedrückter linker Maustaste in die Leinwand; drücken Sie die rec" 
            L"hte Maustaste, um die Leinwand zu löschen.";
         // 
         // panel1
         // 
         this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
         this->panel1->Dock = System::Windows::Forms::DockStyle::Fill;
         this->panel1->Location = System::Drawing::Point(10, 59);
         this->panel1->Name = L"panel1";
         this->panel1->Size = System::Drawing::Size(434, 200);
         this->panel1->TabIndex = 1;
         this->panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::panel1_Paint);
         this->panel1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseMove);
         this->panel1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseDown);
         // 
         // Form1
         // 
         this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
         this->ClientSize = System::Drawing::Size(454, 269);
         this->Controls->Add(this->panel1);
         this->Controls->Add(this->label1);
         this->Name = L"Form1";
         this->Padding = System::Windows::Forms::Padding(10);
         this->Text = L"CreateGraphics-Demo";
         this->ResumeLayout(false);

      }
#pragma endregion
   private: 
      void panel1_MouseMove(Object^  sender, MouseEventArgs^  e) 
      {
         if (e->Button == System::Windows::Forms::MouseButtons::Left)
         {
            Graphics^ gc = panel1->CreateGraphics();
            gc->DrawRectangle(Pens::Blue, e->X, e->Y, 1, 1);
            delete gc;

            koordinaten->Add(Point(e->X, e->Y));
         }
      }

      void panel1_MouseDown(Object^  sender, MouseEventArgs^  e) 
      {
         if (e->Button == System::Windows::Forms::MouseButtons::Right)
         {
            Graphics^ gc = panel1->CreateGraphics();
            gc->Clear(SystemColors::Control);
            delete gc;

            koordinaten->Clear();
         }
      }


      void panel1_Paint(Object^  sender, PaintEventArgs^  e) 
      {
         for each(Point p in koordinaten)
         {
            e->Graphics->DrawRectangle(Pens::Blue, p.X, p.Y, 1, 1);
         }
      }
};
}

