using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Corp3s.Controls
{
    public partial class CustomStatusBarCtrl : Control
    {
        public CustomStatusBarCtrl()
        {
            InitializeComponent();
            Dock = DockStyle.Bottom;
            BackColor = System.Drawing.SystemColors.Control;
            Height = 22;
            Text = "";
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            DrawString(pe.Graphics, ClientRectangle);
        }
        private void DrawBorder(Graphics g, Rectangle rect, Color color)
        {
            Pen pen = new Pen(color);
            Rectangle bound = new Rectangle(0, 0, Width, Height);
            g.DrawRectangle(pen, bound);
            pen.Dispose();
        }

        private void DrawString(Graphics g, Rectangle rect)
        {
            if (Text == null)
                return;
            int x = (int)3;
            int y = (int)4;
            Brush brush = new SolidBrush(ForeColor);
            g.DrawString(Text, Font, brush, x, y);
            brush.Dispose();
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Height = 22;
        }
        protected override void OnTextChanged(EventArgs e)
        {
            SetForeColor(Text);
            base.OnTextChanged(e);            
        }
        protected override void OnParentChanged(EventArgs e)
        {
            try
            {
                Width = Parent.Width;
                Height = 22;
            }
            catch { }
        }

        public void SetForeColor(string msg)
        {
            if (msg == "Unable to communicate with ISAC device.") ForeColor = Color.Red;
            else
                ForeColor = Color.Black;
            Invalidate();
        }
    }
}
