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.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 重绘圆角边框和文字的更多相关文章
- 【原创】重绘winform的GroupBox
功能:重绘winform的GroupBox,以便调整边框颜色和边框宽度 using System; using System.Collections.Generic; using System.Com ...
- 关于echarts绘制树图形的注意事项(文字倾斜、数据更新、缓存重绘问题等)
最近项目中使用到echarts的树操作,对其中几点注意事项进行下总结. 效果图: 1.基础配置 options的配置如下: { tooltip: { trigger: 'item', triggerO ...
- xp系统重绘边框线不显示(首次加载没有触发paint事件)
同样是,重绘边框事件,win7系统显示正常,而xp系统却不显示,这是什么原因造成的呢? 于是,小编开始百度,不停的查找原因,通过一番查找,小编也意外的收获了一些内容: 例如:窗口的拖动,放大,缩小,等 ...
- 【转】【C#】C#重绘windows窗体标题栏和边框
摘要 windows桌面应用程序都有标准的标题栏和边框,大部分程序也默认使用这些样式,一些对视觉效果要求较高的程序,如QQ, MSN,迅雷等聊天工具的样式则与传统的windows程序大不相同,其中迅雷 ...
- css3新增(圆角边框(border-radius),盒子阴影(box-shadow),文字阴影(text-shadow),背景缩放(background-size))
1.圆角边框 border-radius border-radius 属性用于设置元素的外边框圆角 语法:border-radius:length; 参数值可以是数值 或者 百分比 的形式 正方形, ...
- winform重绘控件边框
首先添加一个用户控件 对于重绘边框有三个需要考虑的东西 1:是否显示边框 2:边框颜色 3:边框宽度 所以定义三个私有变量 /// <summary>/// 是否显示边框/// </ ...
- 自行实现透明的控件如Panel GroupBox(使用不需要重绘父控件的效果,一切都因为窗口有了WS_EX_TRANSPARENT属性)
CSDN的Blog开通了.我想这里的Blog作为今后自己回答别人问题的时候,收藏答案的地方很不错呢. 因为社区的贴子早晚都会沉下去,查找起来很不方便,甚至再也找不到呢. Q: http://commu ...
- iOS开发小技巧 -- tableView-section圆角边框解决方案
[iOS开发]tableView-section圆角边框解决方案 tableView圆角边框解决方案 iOS 7之前,图下圆角边框很容易设置 iOS 7之后,tableviewcell的风格不再是圆角 ...
- 理解浏览器的重绘与回流(repaint&&reflow)
今天在做练习的时候,遇到了重绘与回流这个词,表示连个毛都没有听过.遂查之,首先将网上的(http://blog.sina.com.cn/s/blog_8dace7290102wezv.html)关于这 ...
随机推荐
- C# Firefox Session Manager 文件的导出与管理
长时间使用Firefox会产生很多的session文件(使用了插件:Session Manager).这些文件保存了你浏览过的所有的网址.虽然我们可以使用firefox的书签功能.但有时候打开的网址过 ...
- CSS字体大小设置时的参考(转)
from:http://blog.sina.com.cn/s/blog_51cd580b0100gg6y.html font-size 设置的绝对关键字: 以下几个绝对字体大小的设置是有效的.当然他们 ...
- Linux dd——备份命令
Linux学习笔记之备份命令dd 功能:把指定的输入文件拷贝到指定的输出文件中,并且在拷贝过程中可以进行格式转换.可以用该命令实现DOS下的diskcopy命令的作用.先用dd命令把软盘上的数据写成硬 ...
- h5拖放-上传图片预览功能
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Android_UI
* fang@author * Android布局原则: * (1)尽量多使用LinearLayout和RelativeLAyout,不要使用AbsoluteLayout * (2)在布局层次一样的情 ...
- 数据结构与算法分析(2)——表、栈和队列
抽象数据类型 抽象数据类型(ADT)是一系列操作的集合.诸如表.集合.图和他们的操作一起可以看做是抽象数据类型 表 List 表的实现有两种:数组和链表.数组实现的表在插入和删除操作上的花 ...
- Hibernate学习笔记--------2.一多|多多的CRUD
一.一多关系 例如用户(Tb_User)和订单(Tb_Order)之间,一个用户对应了多个订单,多个订单对应一个用户. 除了基本的配置外,需要在用户类(单方)中添加订单的集合同样需要get/set方法 ...
- PHP免费API调用,使用(CURL)
<?phpclass GetApiModel{//获取第三方API //获取身份证信息 //返回json /*{ "errNum": 0, "retMsg" ...
- 关于@see注解
所有三种类型的注释文档都可包含@see标记,它允许我们引用其他类里的文档.对于这个标记,javadoc会生成相应的HTML,将其直接链接到其他文档.格式如下: @see 类名@see 完整类名@see ...
- HTTPS协议学习总结
目录 一:什么是HTTPS协议?二:客户端与服务端如何建立HTTPS协议连接?三:证书.加密协议.信息摘要.签名算法概念解释与关系梳理四:低版本操作系统作为客户端发送HTTPS失败分析五:参考资料 ...