using Exferia_Aplicacion.Visualizacion;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Exferia_Controles
{
    public partial class Exferia_TextBox_ConMascara : Panel
    {
        #region Eventos privados
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.Clear(SystemColors.Window);
            using (Pen borderPen = new Pen(g_mtxt_Principal.Focused ? g_clr_BordeColorFoco : g_clr_BordeColorNormal))
            {
                e.Graphics.DrawRectangle(borderPen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));
            }
            base.OnPaint(e);
        }
        #endregion

        #region Eventos publicos

        private void MaskedTextBox_Refresh(object sender, EventArgs e)
        {
            Invalidate();
        }

        public event KeyPressEventHandler Exferia_TextBox_ConMascara_Evento_KeyPress;
        private void MaskedTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Para que salte el evento en el otro lado
            Exferia_TextBox_ConMascara_Evento_KeyPress?.Invoke(sender, e);
        }

        public event KeyEventHandler Exferia_TextBox_ConMascara_Evento_KeyDown;
        private void MaskedTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            //Para que salte el evento en el otro lado
            Exferia_TextBox_ConMascara_Evento_KeyDown?.Invoke(sender, e);
        }

        public event KeyEventHandler Exferia_TextBox_ConMascara_Evento_KeyUp;
        private void MaskedTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            //Para que salte el evento en el otro lado
            Exferia_TextBox_ConMascara_Evento_KeyUp?.Invoke(sender, e);
        }

        public event EventHandler Exferia_TextBox_ConMascara_Evento_TextChanged;
        private void MaskedTextBox_TextChanged(object sender, EventArgs e)
        {
            //Para que salte el evento en el otro lado
            Exferia_TextBox_ConMascara_Evento_TextChanged?.Invoke(sender, e);
        }

        public event EventHandler Exferia_TextBox_ConMascara_Evento_GotFocus;
        private void MaskedTextBox_GotFocus(object sender, EventArgs e)
        {
            //Para que salte el evento en el otro lado
            Exferia_TextBox_ConMascara_Evento_GotFocus?.Invoke(sender, e);
        }

        public event EventHandler Exferia_TextBox_ConMascara_Evento_LostFocus;
        private void MaskedTextBox_LostFocus(object sender, EventArgs e)
        {
            //Para que salte el evento en el otro lado
            Exferia_TextBox_ConMascara_Evento_LostFocus?.Invoke(this, e);
        }
        #endregion

        #region Propiedades Publicas

        internal bool g_bol_Obligatorio = false;
        public bool Exferia_TextBox_ConMascara_Obligatorio
        {
            set
            {
                g_bol_Obligatorio = value;
                if (g_bol_Obligatorio)
                {
                    Exferia_TextBox_ConMascara_Fondo = Colores.G_COLOR_FONDO_OBLIGATORIO;
                }
                else
                {
                    Exferia_TextBox_ConMascara_Fondo = Colores.G_COLOR_FONDO_BASE;
                }
            }
            get
            {
                return g_bol_Obligatorio;
            }
        }
        public Color Exferia_TextBox_ConMascara_Fondo
        {
            set
            {
                g_mtxt_Principal.BackColor = value;
            }
            get
            {
                return g_mtxt_Principal.BackColor;
            }
        }

        public void Exferia_TextBox_ConMascara_ColorTexto(Color _clr_ColorTexto)
        {
            g_mtxt_Principal.ForeColor = _clr_ColorTexto;
        }

        public void Exferia_TextBox_ConMascara_FuenteTexto(Font _fnt_Texto)
        {
            g_mtxt_Principal.Font = _fnt_Texto;
        }

        public Color g_clr_BordeColorNormal = Color.Black;
        public Color Exferia_TextBox_ConMascara_BordeColor_Normal
        {
            get { return g_clr_BordeColorNormal; }
            set { g_clr_BordeColorNormal = value; }
        }
        public Color g_clr_BordeColorFoco = Color.Red;
        public Color Exferia_TextBox_ConMascara_BordeColor_Foco
        {
            get { return g_clr_BordeColorFoco; }
            set { g_clr_BordeColorFoco = value; }
        }

        public int Exferia_TextBox_ConMascara_MaxLength
        {
            get { return g_mtxt_Principal.MaxLength; }
            set { g_mtxt_Principal.MaxLength = value; }
        }

        public bool Exferia_TextBox_ConMascara_Multiline
        {
            get { return g_mtxt_Principal.Multiline; }
            set { g_mtxt_Principal.Multiline = value; }
        }

        public char Exferia_TextBox_ConMascara_PasswordChar
        {
            get { return g_mtxt_Principal.PasswordChar; }
            set { g_mtxt_Principal.PasswordChar = value; }
        }

        public bool Exferia_TextBox_ConMascara_UseSystemPasswordChar
        {
            get { return g_mtxt_Principal.UseSystemPasswordChar; }
            set { g_mtxt_Principal.UseSystemPasswordChar = value; }
        }

        public int Exferia_TextBox_ConMascara_SelectionStart
        {
            get { return g_mtxt_Principal.SelectionStart; }
            set { g_mtxt_Principal.SelectionStart = value; }
        }

        public int Exferia_TextBox_ConMascara_SelectionLength
        {
            get { return g_mtxt_Principal.SelectionLength; }
            set { g_mtxt_Principal.SelectionLength = value; }
        }

        override
        public string Text
        {
            get { return g_mtxt_Principal.Text; }
            set { g_mtxt_Principal.Text = value; }
        }

        public string Exferia_TextBox_ConMascara_Texto_Inicial
        {
            get { return g_mtxt_Principal.Text; }
            set
            {
                g_mtxt_Principal.Text = value;
            }
        }

        public bool Exferia_TextBox_ConMascara_TabStop
        {
            get { return g_mtxt_Principal.TabStop; }
            set
            {
                g_mtxt_Principal.TabStop = value;
            }
        }

        public HorizontalAlignment Exferia_TextBox_ConMascara_TextAlign
        {
            get { return g_mtxt_Principal.TextAlign; }
            set { g_mtxt_Principal.TextAlign = value; }
        }

        public bool Exferia_TextBox_ConMascara_NoBloquear
        {
            get { return g_mtxt_Principal.Enabled; }
            set
            {
                Focus();
                Enabled = value;
            }
        }

        public void Exferia_TextBox_ConMascara_Focus()
        {
            g_mtxt_Principal.Focus();
            Invalidate();
        }

        public bool Exferia_TextBox_ConMascara_ReadOnly
        {
            get { return g_mtxt_Principal.ReadOnly; }
            set { g_mtxt_Principal.ReadOnly = value; }
        }

        public string Exferia_TextBox_ConMascara_Mask
        {
            get { return g_mtxt_Principal.Mask; }
            set { g_mtxt_Principal.Mask = value; }
        }

        #endregion

        private  MaskedTextBox g_mtxt_Principal;

        public Exferia_TextBox_ConMascara()
        {
            DoubleBuffered = true;
            Padding = new Padding(2);
            Anchor = AnchorStyles.Top | AnchorStyles.Left;
            Height = 22;

            g_mtxt_Principal = new MaskedTextBox();
            g_mtxt_Principal.AutoSize = false;
            g_mtxt_Principal.UseSystemPasswordChar = false;
            g_mtxt_Principal.BorderStyle = BorderStyle.None;
            g_mtxt_Principal.Dock = DockStyle.Fill;

            //Eventos
            g_mtxt_Principal.Enter += new EventHandler(MaskedTextBox_Refresh);
            g_mtxt_Principal.Leave += new EventHandler(MaskedTextBox_Refresh);
            g_mtxt_Principal.Resize += new EventHandler(MaskedTextBox_Refresh);
            g_mtxt_Principal.EnabledChanged += new EventHandler(MaskedTextBox_Refresh);
            g_mtxt_Principal.KeyPress += new KeyPressEventHandler(MaskedTextBox_KeyPress);
            g_mtxt_Principal.KeyDown += new KeyEventHandler(MaskedTextBox_KeyDown);
            g_mtxt_Principal.KeyUp += new KeyEventHandler(MaskedTextBox_KeyUp);
            g_mtxt_Principal.TextChanged += new EventHandler(MaskedTextBox_TextChanged);
            g_mtxt_Principal.GotFocus += new EventHandler(MaskedTextBox_GotFocus);
            g_mtxt_Principal.LostFocus += new EventHandler(MaskedTextBox_LostFocus);

            Controls.Add(g_mtxt_Principal);
        }

       
    }
}
