using System;

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

namespace GroupBox
{
    public partial class GroupBox : UserControl
    {
        public GroupBox()
        {
            InitializeComponent();
        }

        private void GroupBox_Paint(object sender, PaintEventArgs e)
        {
            Pen drawingPen = new Pen(Color.Black, 1);

            Graphics g = e.Graphics;
            g.DrawLine(drawingPen, 0, 7, ClientRectangle.Width, 7);
            g.DrawLine(drawingPen, 0, 7, 0, ClientRectangle.Height);
            g.DrawLine(drawingPen, 0, ClientRectangle.Height-1, 
                ClientRectangle.Width, ClientRectangle.Width-1);
            g.DrawLine(drawingPen, ClientRectangle.Width-1, 7, 
                ClientRectangle.Width-1, ClientRectangle.Height);
        }

        private void label1_TextChanged(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            SizeF size = g.MeasureString(label1.Text, label1.Font);

            label1.Width = (int)size.Width + 4;
        }

        public string Title 
        {         
            get
            {
                return label1.Text;
            }

            set
            {
                label1.Text = value;
                Invalidate();
            }
        }
    }
}