search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C#在畫面畫出元件框(使用自訂GroupBox)做出UI版面區隔 – jashliao部落格

C#在畫面畫出元件框(使用自訂GroupBox)做出UI版面區隔

 

資料來源:http://wahahastudynote.blogspot.tw/2013/05/c-groupbox.html

 

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

namespace SYRIS_BCard_Easy
{
    class myGroupBox : GroupBox
    {

//SYRIS_BCard_Easy used

//http://wahahastudynote.blogspot.tw/2013/05/c-groupbox.html
        private Color _BorderColor = Color.Black;
        [Description(“設定或取得外框顏色”)]

        public Color BorderColor
        {
            get { return _BorderColor; }
            set { _BorderColor = value; }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            //取得text字型大小
            Size FontSize = TextRenderer.MeasureText(this.Text,
                                                     this.Font);
            //畫框線
            Rectangle rec = new Rectangle(e.ClipRectangle.Y,
                                          this.Font.Height / 2,
                                          e.ClipRectangle.Width – 1,
                                          e.ClipRectangle.Height – 1 –
                                          this.Font.Height / 2);

            e.Graphics.DrawRectangle(new Pen(BorderColor), rec);

            //填滿text的背景
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor),
                new Rectangle(6, 0, FontSize.Width, FontSize.Height));

            //text
            e.Graphics.DrawString(this.Text, this.Font,
                new Pen(this.ForeColor).Brush, 6, 0);
        }
    }
}

 

 

 

 



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦