//ライセンス情報はAgeOnフォルダのLISENCEフォルダを参照してください
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using System.Runtime.InteropServices;
using System.Linq;


namespace AgeOnUpdate
{
    class ProgressBarForm
    {
        public Form popUp;
        public Label textLabel;
        public ProgressBar progressBar;
        public Button exitButton;

        public delegate void SimpleMethod();
        public SimpleMethod closeDele;

        public ProgressBarForm()
        {
            this.closeDele = Cloose;

            //フォーム
            popUp = new Form();
            popUp.Hide();
            popUp.ShowInTaskbar = false;
            popUp.ShowIcon = false;
            popUp.FormBorderStyle = FormBorderStyle.FixedSingle;
            popUp.StartPosition = FormStartPosition.Manual;
            popUp.TopMost= true;
            /*popUp.Location =
                ViewMediator.worldMapMain.worldMapControlView.panelMap.PointToScreen(
                ViewMediator.worldMapMain.worldMapControlView.panelMap.Location);*/
            popUp.Size = new Size(350, 150);
            popUp.MaximumSize = new Size(350, 150);
            popUp.MinimumSize = new Size(350, 150);
            popUp.Text = "アップデート中です";
            //popUp.Owner = Const.form.mainForm.control;

            popUp.FormClosing += new FormClosingEventHandler(popUp_FormClosing);
            //ラベル
            textLabel = new Label();
            textLabel.Location = new System.Drawing.Point(50, 15);
            textLabel.Name = "Label1";
            textLabel.Size = new System.Drawing.Size(300, 30);
            textLabel.TabIndex = 0;
            //textLabel.Text = "受信しています";

            //プログレスバー
            progressBar = new ProgressBar();
            progressBar.Location = new System.Drawing.Point(25, 50);
            progressBar.Name = "ProgressBar1";
            progressBar.Size = new System.Drawing.Size(290, 25);
            progressBar.TabIndex = 1;
            progressBar.Minimum = 0;

            exitButton = new Button();
            exitButton.Location = new Point(130, 90);
            exitButton.AutoSize = true;
            exitButton.Text = "中止する";
            exitButton.Click += new EventHandler(exitButton_Click);

            popUp.Controls.Add(textLabel);
            popUp.Controls.Add(progressBar);
            //popUp.Controls.Add(exitButton);
        }

        public void SetUpTwo()
        {
            popUp.Location = new Point(
                System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width/ 2,
                System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2);
            progressBar.Value = 0;
            popUp.ShowDialog();
        }

        private void popUp_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            if (popUp.Visible == true)
            {
                this.popUp.BeginInvoke((Action)(() => this.closeDele()));
                //Closing();
            }
        }
        private void Cloose()
        {
            popUp.Close();
            popUp.Dispose();
        }
        //呼び出し側のクロース処理を行う
        private void exitButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (popUp.Visible == true)
                {
                    this.popUp.BeginInvoke((Action)(() => this.closeDele()));
                    //Closing();
                }
            }
            catch { ;}
        }
        //ウィンドウを隠す
        public void Closing()
        {
            popUp.Hide();
            popUp.Dispose();
            progressBar.Dispose();
            textLabel.Dispose();
            textLabel.Dispose();
            closeDele = null;
        }
    }
}
