개발관련/C#

Winform Control 안쪽 여백 제거

Diademata 2018. 4. 8. 12:49
반응형

namespace UI

{

    class BorderGroupBox : GroupBox

    {

        private Color _borderColor = Color.Black;

        private Rectangle _displayRectangle;

        protected override void OnResize(EventArgs e)

        {

            base.OnResize(e);

            _displayRectangle = base.ClientRectangle;

            _displayRectangle.Y = this.Padding.Top;

            _displayRectangle.X = this.Padding.Left;

            _displayRectangle.Height -= this.Padding.Top;

            _displayRectangle.Width -= this.Padding.Left;

            this.PerformLayout();

        }

        protected override void OnPaint(PaintEventArgs e)

        {

            Size tSize = TextRenderer.MeasureText(this.Text, this.Font);

            Rectangle borderRect = e.ClipRectangle;

            borderRect.Y = (borderRect.Y + (tSize.Height / 2));

            borderRect.Height = (borderRect.Height - (tSize.Height / 2));

            ControlPaint.DrawBorder(e.Graphics, borderRect, this._borderColor, ButtonBorderStyle.Solid);

            Rectangle textRect = e.ClipRectangle;

            textRect.X = (textRect.X + 6);

            textRect.Width = tSize.Width;

            textRect.Height = tSize.Height;

            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect);

            e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);

        }

        public override Rectangle DisplayRectangle

        {

            get => this._displayRectangle;

        }

        [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]

        public Color BorderColor

        {

            get { return this._borderColor; }

            set { this._borderColor = value; }

        }

    }

}



반응형