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. Xcode中的Info.plist字段列表详解

    Info.plist用于向iOS提供关于app,bundle或者framework的一些重要信息.它指定了比如一个应用应该怎样启动,它如何被本地化,应用的名称,要显示的图标,还有更多.Info.pli ...

  2. css布局模型之绝对定位与相对定位

    1. 绝对定位,absolute 如果想为元素设置层模型中的绝对定位,需要设置position:absolute(表示绝对定位),这条语句的作用将元素从文档流中拖出来,然后使用left.right.t ...

  3. hihocoder 1163 博弈游戏·Nim游戏

    1163 : 博弈游戏·Nim游戏 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob. Alice与Bob总是在进行各种各样的 ...

  4. Rshare Pro是否可以放入至客户企业App Store?

    现在很多客户内部部署了苹果授权的企业内部的AppStore,我们的Rshare Pro 是完全允许放入企业搭建的AppStore平台中.但每份需要收费20美元,换成人民币是120元.

  5. html转图片

    using System.IO; using System.Drawing; using System.Threading; using System.Windows.Forms; public cl ...

  6. ASP清除字串中的重复字符

    <% Function Test(str) dim intLen,i,strTemp,aryTest intLen = Len(str) strTemp = "" aryTe ...

  7. zabbix数据存储

    一.zabbix数据库 zabbix-server将采集到的数据存储在数据库中,最常用的Mysql,数据存储的大小和每秒处理的数据量有关,数据存储取决于每秒处理的数据量和Housekeeper的删除数 ...

  8. HW--漂亮度2(测试通过)

    总结:几个函数的使用 (1)  int num=Integer.parseInt(str[0]); //将第一个字符串转成整形数,表示名字个数 (2) String string1=str[i].to ...

  9. 解决DropDownList 有一个无效 SelectedValue,因为它不在项目列表中。这是怎么回事?

    产生错误原因: 绑定在DropDownList的时候 DropDownList没有对应的值 查了一下MSDN:DropDownList.SelectedValue 属性: 此属性返回选定的 ListI ...

  10. struts2中<s:property>的用法

    1,访问Action值栈中的普通属性: <s:property value="attrName"/> 2,访问Action值栈中的对象属性(要有get set方法):  ...