using FCOMMON;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project.Dialog
{
    public partial class fMsgWindow : fBase
    {
        private Boolean fMove = false;
        private Point MDownPos;
        private string _msg = string.Empty;
        public Project.MessageWindow.eMsgNo ID { get; set; }

        /// <summary>
        /// 사용자가 이 창을 닫을수 있는가?
        /// </summary>
        public Boolean EnableUserClose
        {
            get { return _enableuserclose; }
            set
            {
                _enableuserclose = value;
                if (!EnableUserClose) arLabel1.Visible = false;
            }
        }
        private Boolean _enableuserclose = true;

        public fMsgWindow(string msg)
        {
            EnableUserClose = true;
            InitializeComponent();
            this.KeyDown += (s1, e1) => { if (EnableUserClose && e1.KeyCode == Keys.Escape) this.Close(); };
            this._msg = msg;
            arLabel1.Text = msg;
            ID = 0;
            arLabel1.MouseMove += label1_MouseMove;
            arLabel1.MouseUp += label1_MouseUp;
            arLabel1.MouseDown += label1_MouseDown;
            arLabel1.MouseDoubleClick += label1_MouseDoubleClick;
            arLabel1.Click += arLabel1_Click;
        }

        private void fMsg_Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
        }

        public void SetText(string m)
        {
            this.arLabel1.Text = m;
            this.arLabel1.Refresh();
        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (fMove)
            {
                Point offset = new Point(e.X - MDownPos.X, e.Y - MDownPos.Y);
                this.Left += offset.X;
                this.Top += offset.Y;
                offset = new Point(0, 0);
            }
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            fMove = false;
        }

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            MDownPos = new Point(e.X, e.Y);
            fMove = true;
        }

        private void label1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (EnableUserClose)
                this.Close();
        }

        private void arLabel1_Click(object sender, EventArgs e)
        {
            if (EnableUserClose)
                this.Close();
        }

        private void arLabel1_Click_1(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (EnableUserClose)
                this.Close();
        }
    }
}
