private void GroupBox_Paint(object sender, PaintEventArgs e)
{
if (sender != null && sender is GroupBox)
{
GroupBox gbx = sender as GroupBox;
e.Graphics.Clear(gbx.BackColor);
Color color = Color.Black;
Pen p = new Pen(color, 1);
int w = gbx.Width;
int h = gbx.Height;
Brush b = null;
if (gbx.Parent != null)
b = new SolidBrush(gbx.Parent.BackColor);
else
b = new SolidBrush(this.BackColor);
//绘制直线
e.Graphics.DrawLine(p, 3, h - 1, w - 4, h - 1); //bottom
e.Graphics.DrawLine(p, 0, h - 4, 0, 12); //left
e.Graphics.DrawLine(p, w - 1, h - 4, w - 1, 12); //right
e.Graphics.FillRectangle(b, 0, 0, w, 8);
e.Graphics.DrawLine(p, 3, 8, 10, 8); //lefg top
e.Graphics.DrawLine(p, //right top
e.Graphics.MeasureString(gbx.Text,
gbx.Font).Width + 8, 8, w - 4, 8);
//绘制文字
e.Graphics.DrawString(gbx.Text, gbx.Font, Brushes.Blue, 10, 0); //title
//绘制弧线
e.Graphics.DrawArc(p, new Rectangle(0, 8, 10, 10), 180, 90); //left top
e.Graphics.DrawArc(p, new Rectangle(w - 11, 8, 10, 10), 270, 90); //right top
e.Graphics.DrawArc(p, new Rectangle(0, h - 11, 10, 10), 90, 90); //left bottom
e.Graphics.DrawArc(p, new Rectangle(w - 11, h - 11, 10, 10), 0, 90);//right bottom
}
}

因为 GroupBox 自带的灰色边框太过难看,所以尝试着对其重新绘制了一个新的边框。最开始不带圆角,感觉不太舒服,然后又添加了圆角,不过四个圆角的外侧还是与GroupBox外的颜色不太一样。试着用过一次路径来做,但是GroupBox内侧会有污点,不知道是怎么回事。

上面是没有污点,但是四个圆角外有细微颜色不同的,下面是对四个圆角外侧也做了着色,但是 GroupBox 内却出现污点的。如果有哪位高人能够帮忙解释一下污点的问题和提出一些解决方法,本人感激不尽

        private void GroupBox_Paint(object sender, PaintEventArgs e)
{
if (sender != null && sender is GroupBox)
{
GroupBox gbx = sender as GroupBox;
e.Graphics.Clear(gbx.BackColor);
Color color = Color.Black;
Pen p = new Pen(color, 1);
int w = gbx.Width;
int h = gbx.Height;
Brush b = null;
if (gbx.Parent != null)
b = new SolidBrush(gbx.Parent.BackColor);
else
b = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(Brushes.PapayaWhip, new Rectangle(0, 0, w, h));
GraphicsPath gp = new GraphicsPath();
gp.AddArc(new Rectangle(0, 8, 10, 10), 180, 90); //left top
gp.AddLine(0, h - 4, 0, 12); //left
gp.AddArc(new Rectangle(0, h - 11, 10, 10), 90, 90); //left bottom
gp.AddLine(3, h - 1, w - 4, h - 1); //bottom
gp.AddArc(new Rectangle(w - 11, h - 11, 10, 10), 0, 90); //right bottom
gp.AddLine(w - 1, h - 4, w - 1, 12); //right
gp.AddArc(new Rectangle(w - 11, 8, 10, 10), 270, 90); //right top
gp.AddLine(3, 8, w - 4, 8); //top
e.Graphics.FillRegion(Brushes.White, new Region(gp));
//绘制直线
e.Graphics.DrawLine(p, 3, h - 1, w - 4, h - 1); //bottom
e.Graphics.DrawLine(p, 0, h - 4, 0, 12); //left
e.Graphics.DrawLine(p, w - 1, h - 4, w - 1, 12); //right
e.Graphics.FillRectangle(b, 0, 0, w, 8);
e.Graphics.DrawLine(p, 3, 8, 10, 8); //lefg top
e.Graphics.DrawLine(p, //right top
e.Graphics.MeasureString(gbx.Text,
gbx.Font).Width + 8, 8, w - 4, 8);
//绘制文字
e.Graphics.DrawString(gbx.Text, gbx.Font, Brushes.Blue, 10, 0); //title
//绘制弧线
e.Graphics.DrawArc(p, new Rectangle(0, 8, 10, 10), 180, 90); //left top
e.Graphics.DrawArc(p, new Rectangle(w - 11, 8, 10, 10), 270, 90); //right top
e.Graphics.DrawArc(p, new Rectangle(0, h - 11, 10, 10), 90, 90); //left bottom
e.Graphics.DrawArc(p, new Rectangle(w - 11, h - 11, 10, 10), 0, 90);//right bottom
}
}

GroupBox 重绘圆角边框和文字的更多相关文章

  1. 【原创】重绘winform的GroupBox

    功能:重绘winform的GroupBox,以便调整边框颜色和边框宽度 using System; using System.Collections.Generic; using System.Com ...

  2. 关于echarts绘制树图形的注意事项(文字倾斜、数据更新、缓存重绘问题等)

    最近项目中使用到echarts的树操作,对其中几点注意事项进行下总结. 效果图: 1.基础配置 options的配置如下: { tooltip: { trigger: 'item', triggerO ...

  3. xp系统重绘边框线不显示(首次加载没有触发paint事件)

    同样是,重绘边框事件,win7系统显示正常,而xp系统却不显示,这是什么原因造成的呢? 于是,小编开始百度,不停的查找原因,通过一番查找,小编也意外的收获了一些内容: 例如:窗口的拖动,放大,缩小,等 ...

  4. 【转】【C#】C#重绘windows窗体标题栏和边框

    摘要 windows桌面应用程序都有标准的标题栏和边框,大部分程序也默认使用这些样式,一些对视觉效果要求较高的程序,如QQ, MSN,迅雷等聊天工具的样式则与传统的windows程序大不相同,其中迅雷 ...

  5. css3新增(圆角边框(border-radius),盒子阴影(box-shadow),文字阴影(text-shadow),背景缩放(background-size))

    1.圆角边框  border-radius border-radius 属性用于设置元素的外边框圆角 语法:border-radius:length; 参数值可以是数值 或者 百分比 的形式 正方形, ...

  6. winform重绘控件边框

    首先添加一个用户控件 对于重绘边框有三个需要考虑的东西 1:是否显示边框 2:边框颜色 3:边框宽度 所以定义三个私有变量 /// <summary>/// 是否显示边框/// </ ...

  7. 自行实现透明的控件如Panel GroupBox(使用不需要重绘父控件的效果,一切都因为窗口有了WS_EX_TRANSPARENT属性)

    CSDN的Blog开通了.我想这里的Blog作为今后自己回答别人问题的时候,收藏答案的地方很不错呢. 因为社区的贴子早晚都会沉下去,查找起来很不方便,甚至再也找不到呢. Q: http://commu ...

  8. iOS开发小技巧 -- tableView-section圆角边框解决方案

    [iOS开发]tableView-section圆角边框解决方案 tableView圆角边框解决方案 iOS 7之前,图下圆角边框很容易设置 iOS 7之后,tableviewcell的风格不再是圆角 ...

  9. 理解浏览器的重绘与回流(repaint&&reflow)

    今天在做练习的时候,遇到了重绘与回流这个词,表示连个毛都没有听过.遂查之,首先将网上的(http://blog.sina.com.cn/s/blog_8dace7290102wezv.html)关于这 ...

随机推荐

  1. [AngularJS] Introduction to angular-formly

    <!DOCTYPE html> <html> <head> <!-- Each of these scripts are the latest version ...

  2. EasyARM i.mx28学习笔记——开箱试用总结

    0 前言     本月初(2014年8月)购买了周立功的EasyARM开发板,主控为EasyARM i.mx287.出于下面几个理由购买了该开发板.     [1]主要原因,有人约我一起学习一起使用该 ...

  3. forward_list例子

    9.28 编写函数,接受一个forward_list<string>和两个string共三个参数.函数应在链表中查找第一个string,并将第二个string插入到紧接着第一个string ...

  4. Linq的小知识(一),大家可以学习一下

    linq的简介 lLINQ是Language Integrated Query的简称,它是集成在.NET编程语言中的一种特性.已成为编程语言的一个组成部分,在编写程序时可以得到很好的编译时语法检查,丰 ...

  5. httperf ---linux web站点压力测试

    一.工具下载&&安装 软件获取 ftp://ftp.hpl.hp.com/pub/httperf/ 这里使用的是如下的版本 ftp://ftp.hpl.hp.com/pub/httpe ...

  6. DROP--删除表

    DROP TABLE table_name; 说明: 1.必须有表的权限 2.表不能有外键约束

  7. 关于Git的暂存区这个概念的理解.

    Git中的暂存区成为stage或者是index.可以理解成一个"提交任务".Git暂存区是Git最成功的设计之一,但是也是最难理解的. 暂存区是一个介于工作区和版本库的中间状态.当 ...

  8. Greedy

    在现实世界中,有这样一类问题:它有n个输入,而它的解就由这n个输入的某个子集组成,不过这个子集必须满足某些事先给定的条件.把那些必须满足的条件称为约束条件:而把满足约束条件的子集称为该问题的可行解.问 ...

  9. 简单的ROT13码编码与解码

    ROT13码意思是将字母左移13位.如'A' ↔ 'N', 'B' ↔ 'O','V' ↔ 'I'. 下面实现ROT13码的解码. function rot13(str) { var arr = [] ...

  10. socket编程发送GET请求

    可以根据几根url地址,分析出主机,地址,协议等,然后用封装成的类拼接成GET请求信息,用fsockopen连接主机,进行读取操作,获取响应信息,打印 <?php //http连接接口 inte ...