其實微軟的GroupBox是沒辦法設定外框和字型的顏色的,所以我們就來自己加
參考 http://social.msdn.microsoft.com/forums/en-US/winforms/thread/cfd34dd1-b6e5-4b56-9901-0dc3d2ca5788/
寫了一個GroupBox控制項
參考 http://social.msdn.microsoft.com/forums/en-US/winforms/thread/cfd34dd1-b6e5-4b56-9901-0dc3d2ca5788/
寫了一個GroupBox控制項
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public class myGroupBox:GroupBox { private Color _BorderColor = Color.Red; [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.C lipRectangle.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); //base.OnPaint(e); } } |
留言