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] Best Practise - Resolve promises in router, defer controllers

    See more:http://toddmotto.com/opinionated-angular-js-styleguide-for-teams/ /** * Created by Answer12 ...

  2. 开源PaaS产品介绍

    简介 本文主要介绍一下PaaS领域两个著名的开源软件: Cloud Foundry和OpenShift. [广告]如果你喜欢本博客,请点此查看本博客所有文章:http://www.cnblogs.co ...

  3. 列式存储 V.S. 行式存储

    列式数据库 http://zh.wikipedia.org/wiki/%E5%88%97%E5%BC%8F%E6%95%B0%E6%8D%AE%E5%BA%93 列式存储与行式存储 http://my ...

  4. com.domain.bean

    package com.domain.bean; import java.util.LinkedHashMap; import java.util.Map; public class TmpBean ...

  5. Lucene全文检索系列(一)

    1. Lucene简介 Lucene是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎.Lucene以其方便使用.快速实施以及灵活性受到广泛的关注.它可以方便地嵌入到各种应用中实现针对应用的全文 ...

  6. C语言---翻译过程

    c的实现中包括两种环境: 1.翻译环境(translation environment):源程序---->机器指令 2.执行环境(execution environment):执行机器指令 这两 ...

  7. #284 div.2 C.Crazy Town

    C. Crazy Town   Crazy Town is a plane on which there are n infinite line roads. Each road is defined ...

  8. 简单学JAVA之---接口的定义与实现

    为了巩固自己学习的知识,可能会对自己以后所学的知识做一个小结,今天就来一篇接口的定义与实现. 在java中,我们可以通过继承得到另一个类中的方法,但是这个仅仅满足继承一个方法,那有办法可以多个继承不, ...

  9. 服务端缓存HttpRuntime.Cache的使用

    HttpRuntime.Cache.Insert("缓存key", "缓存content", null, DateTime.Now.AddMinutes(3), ...

  10. ASP过滤HTML标签

    <% Function RemoveHTML(strHTML) Dim objRegExp, Match, Matches Set objRegExp = New Regexp objRegEx ...