c++ windows forms close window when receive data serial
<p>I'm new here, and new to windows forms.
I'm trying to make the window wait for receiving data from an arduino, when data is recieved the window must close.
I have been able to that so far, but i can't do anything in the window when it opens. Du you have any suggestens how to do that.</p>

<p>The code here:
    </p>

<pre><code>#pragma once

namespace CppWinForm1 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;


public ref class password : public System::Windows::Forms::Form
{
public:
    password(void)
    {
        InitializeComponent();
        this-&gt;serialPort2-&gt;Open();
    }

protected:
    /// &lt;summary&gt;
    /// Clean up any resources being used.
    /// &lt;/summary&gt;
    ~password()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Label^  label1;
public: System::IO::Ports::SerialPort^  serialPort2;
private: System::Windows::Forms::Timer^  timer1;
private: System::Windows::Forms::Button^  button1;
private: System::ComponentModel::IContainer^  components;

private:


  #pragma region Windows Form Designer generated code

    void InitializeComponent(void)
    {
        this-&gt;components = (gcnew System::ComponentModel::Container());
        System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(password::typeid));
        this-&gt;label1 = (gcnew System::Windows::Forms::Label());
        this-&gt;serialPort2 = (gcnew System::IO::Ports::SerialPort(this-&gt;components));
        this-&gt;timer1 = (gcnew System::Windows::Forms::Timer(this-&gt;components));
        this-&gt;button1 = (gcnew System::Windows::Forms::Button());
        this-&gt;SuspendLayout();
        // 
        // label1
        // 
        this-&gt;label1-&gt;AutoSize = true;
        this-&gt;label1-&gt;Location = System::Drawing::Point(192, 70);
        this-&gt;label1-&gt;Name = L"label1";
        this-&gt;label1-&gt;Size = System::Drawing::Size(330, 25);
        this-&gt;label1-&gt;TabIndex = 0;
        this-&gt;label1-&gt;Text = L"Indtast password på DE2 boardet";
        this-&gt;label1-&gt;Click += gcnew System::EventHandler(this, &amp;password::label1_Click);
        // 
        // serialPort2
        // 
        this-&gt;serialPort2-&gt;PortName = L"COM5";
        // 
        // timer1
        // 
        this-&gt;timer1-&gt;Enabled = true;
        this-&gt;timer1-&gt;Interval = 1;
        this-&gt;timer1-&gt;Tick += gcnew System::EventHandler(this, &amp;password::timer1_Tick);
        // 
        // button1
        // 
        this-&gt;button1-&gt;Location = System::Drawing::Point(197, 123);
        this-&gt;button1-&gt;Name = L"button1";
        this-&gt;button1-&gt;Size = System::Drawing::Size(325, 57);
        this-&gt;button1-&gt;TabIndex = 1;
        this-&gt;button1-&gt;Text = L"Tilbage";
        this-&gt;button1-&gt;UseVisualStyleBackColor = true;
        this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;password::button1_Click_1);
        // 
        // password
        // 
        this-&gt;AutoScaleDimensions = System::Drawing::SizeF(12, 25);
        this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this-&gt;ClientSize = System::Drawing::Size(738, 280);
        this-&gt;Controls-&gt;Add(this-&gt;button1);
        this-&gt;Controls-&gt;Add(this-&gt;label1);
        this-&gt;Icon = (cli::safe_cast&lt;System::Drawing::Icon^&gt;(resources-&gt;GetObject(L"$this.Icon")));
        this-&gt;Name = L"password";
        this-&gt;Text = L"password";
        this-&gt;Load += gcnew System::EventHandler(this, &amp;password::password_Load);
        this-&gt;ResumeLayout(false);
        this-&gt;PerformLayout();

    }
#pragma endregion
private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
}


private: System::Void password_Load(System::Object^  sender, System::EventArgs^  e) {
    this-&gt;timer1-&gt;Start();
}

private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
    this-&gt;serialPort2-&gt;WriteLine("3");
    char ch = this-&gt;serialPort2-&gt;ReadLine()[0];
    int x = ch - 48;
    if (x == 1)
    {
        this-&gt;serialPort2-&gt;Close();
        this-&gt;timer1-&gt;Stop();
        Close();
    }
}

private: System::Void button1_Click_1(System::Object^  sender, System::EventArgs^  e) {
    this-&gt;serialPort2-&gt;Close();
    this-&gt;timer1-&gt;Stop();
    Close();
}
};
}
</code></pre>