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 BorderPanelControl : Panel
    {
        private string m_sText;
        private Font m_fFont;

        public BorderPanelControl()
        {
            m_fFont = new Font(FontFamily.GenericSerif, (float)8.25, FontStyle.Regular);
            InitializeComponent();
        }

        public string FrameText
        {
            get { return m_sText; }
            set
            {
                m_sText = value;
                Invalidate();
            }
        }

        public Font FrameFont
        {
            get { return m_fFont; }
            set
            {
                m_fFont = value;
                Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            SizeF textSize = e.Graphics.MeasureString(m_sText, m_fFont);
            int height = (int)(textSize.Height / 2);

            if (m_sText == null || m_sText == "")
            {
                height = -1;
            }

            Rectangle bound = new Rectangle(0, 0 + height + 1, Size.Width - 1, Size.Height - height - 2);            
            e.Graphics.DrawRectangle(new Pen(ForeColor), bound);
            e.Graphics.FillRectangle(new SolidBrush(BackColor), 2, 0, (int)textSize.Width + 1, (int)textSize.Height);
            e.Graphics.DrawString(m_sText, m_fFont, new SolidBrush(ForeColor), 3, 0);
        }
    }
}
