【原创】重绘winform的GroupBox
功能:重绘winform的GroupBox,以便调整边框颜色和边框宽度
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D; namespace JSHYSC_CtrlLib
{
public partial class Ctrl_GroupBox : GroupBox
{
private Color borderLineColor =System.Drawing.SystemColors.GradientActiveCaption;
/// <summary>
/// 边框线颜色
/// </summary>
public Color BorderLineColor
{
get { return borderLineColor; }
set { borderLineColor = value; }
} private float borderLineWidth = 1;
/// <summary>
/// 边框线宽度
/// </summary>
public float BorderLineWidth
{
get { return borderLineWidth; }
set { borderLineWidth = value; }
} public Ctrl_GroupBox()
{
InitializeComponent();
} protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e); e.Graphics.Clear(base.BackColor); //圆弧直径长度
int radius = 20;
int width = e.ClipRectangle.Width, height = e.ClipRectangle.Height;
int titleStartX = 15;
float titleWidth = e.Graphics.MeasureString(base.Text, base.Font).Width;
float titleHeight = e.Graphics.MeasureString(base.Text, base.Font).Height; Pen pen = new Pen(borderLineColor, (float)borderLineWidth); //左上角圆弧
e.Graphics.DrawArc(pen, new Rectangle(0, (int)(titleHeight / 2), radius, radius), 180, 90); //上边框,标题前半部分
e.Graphics.DrawLine(pen, radius / 2, (titleHeight - 1) / 2, radius + titleStartX-3, (titleHeight - 1) / 2); //画笔
SolidBrush brush = new SolidBrush(Color.Black);
Font font = new System.Drawing.Font("宋体", 10, FontStyle.Bold);
//标题
e.Graphics.DrawString(base.Text, font, brush, radius / 2 + titleStartX, 0); //上边框,标题右半部分
e.Graphics.DrawLine(pen, radius / 2 + titleStartX + titleWidth+3, (titleHeight - 1) / 2, (width - 1) - radius / 2, (titleHeight - 1) / 2); //右上角圆弧
e.Graphics.DrawArc(pen, new Rectangle((width - 1) - radius, (int)(titleHeight / 2), radius, radius), 270, 90); //右边框
e.Graphics.DrawLine(pen, width - 1, (int)(titleHeight / 2) + radius / 2, width - 1, (height - 1) - radius / 2); //右下角圆弧
e.Graphics.DrawArc(pen, new Rectangle((width - 1) - radius, (height - 1) - radius, radius, radius), 0, 90); //下边框
e.Graphics.DrawLine(pen, (width - 1) - radius / 2, height - 1, radius / 2, height - 1); //左下角圆弧
e.Graphics.DrawArc(pen, new Rectangle(0, (height - 1) - radius, radius, radius), 90, 90); //左边框
e.Graphics.DrawLine(pen, 0, (height - 1) - radius / 2, 0, (int)(titleHeight / 2) + radius / 2);
}
}
}
【原创】重绘winform的GroupBox的更多相关文章
- 重绘Winform窗体
本文转载自:http://www.cnblogs.com/encoding/p/5603080.html 按照惯例,先来几张样例图(注:为了展示窗口阴影效果,截图范围向外扩展了些,各位凭想象吧). 还 ...
- WinForm中重绘TabControl选项卡标题
最近开发WinForm频繁使用了TabControl控件,这个控件的选项卡没有BackgroundImage这个属性,那么如何为其各个选项卡添加背景图片呢?(这里说的是每个TabPage的头部,也就是 ...
- [DForm]我也来做自定义Winform之另类标题栏重绘
据说得有楔子 按照惯例,先来几张样例图(注:为了展示窗口阴影效果,截图范围向外扩展了些,各位凭想象吧). 还要来个序 其实,很多年没写过Winform了,前端时间在 ...
- c#winform自定义窗体,重绘标题栏,自定义控件学习
c#winform自定义窗体,重绘标题栏 虽然现在都在说winform窗体太丑了,但是我也能尽量让桌面应用程序漂亮那么一点点话不多说,先上图 重绘标题栏先将原生窗体设置成无边框,FormBoderSt ...
- 『转载』C# winform 中dataGridView的重绘(进度条,虚线,单元格合并等)
原文转载自:http://hi.baidu.com/suming/item/81e45b1ab9b4585f2a3e2243 最近比较浅的研究了一下dataGridView的重绘,发现里面还是有很多东 ...
- WinForm TreeView节点重绘,失去焦点的高亮显示
当用户焦点离开TreeView时,TreeView选中节点仍然高亮,但是颜色符合主题. 设置TreeView.HideSelection = False;可让选中节点保持高亮. 添加重绘事件 Tree ...
- 使用重绘项美化WinForm中的控件
如果你觉得项目中的ComboBox.ListBox或其它的Winforms控件不能满足你的显示要求,包括窗体在内很多控件都支持重绘修改显示样式.下面的示例完成对ComBox数据项的重绘,希望能起到抛砖 ...
- WinForm中的重绘 - 按钮等控件的背景渐变色重绘
注:brush通过起止坐标来控制重绘范围及方向.比如从上到下渐变时,brush第二个Point参数是左下角坐标. private void PaintGradientBackground(Button ...
- winform控件大小改变是防止背景重绘导致的闪烁(转载)
在工作中需要做一个伸缩控件,这个自定义控件继承于Panel.这个伸缩控件分为两个部分,头部是一个自定义组件,伸缩控件的背景为灰色,头部背景要求白色.伸缩控件在点击按钮时会重绘,同时他内部的控件也会重绘 ...
随机推荐
- 解决Admob Banner首次展示不显示的问题
Admob banner在第一次虽然加载成功了,但是却不显示.然后等待60秒刷新自动刷新,banner就能正常显示. 如果你没遇到过这种情况,那可能你用的不是集成在play-services里的库,因 ...
- 帮助中心 7D-我的私家设计师 设计师品牌服饰集成网 7D服装定制!
帮助中心 7D-我的私家设计师 设计师品牌服饰集成网 7D服装定制! 关于我们
- oracle实例名,数据库名,服务名等概念差别与联系
数据库名.实例名.数据库域名.全局数据库名.服务名 这是几个令非常多刚開始学习的人easy混淆的概念.相信非常多刚開始学习的人都与我一样被标题上这些个概念搞得一头雾水.我们如今就来把它们弄个明确. 一 ...
- vs快捷键
Ctrl+E,D ----格式化全部代码 Ctrl+A+K+FCtrl+E,F ----格式化选中的代码 Ctrl+K+FCTRL + SHIFT + B生成解决方案 Alt+B+B 或 F6 生成当 ...
- vue+webpack一些知识
使用mac的用户需要获取权限才可以使用npm install指令 设置node目录的权限指令 sudo chmod -R 777 /usr/local/lib/node_modules/ 大家都知道国 ...
- box-shadow属性
一.定义和用法 box-shadow属性 向框添加一个或多个阴影. 二.语法 box-shadow: h-shadow v-shadow blur spread color inset; h-shad ...
- 分布式传输协调程序MSDTC配置
尊重原著作:本文转载自http://blog.csdn.net/wilsonke/article/details/8468438 配置说明文件:http://files.cnblogs.com/hlx ...
- Spring MVC JSON 实现JsonSerializer Date类型转换
转载至:http://blog.csdn.net/lantianzhange/article/details/40920933 在Spring MVC中存在两大类的类型转换,一类是Json,一个是Sp ...
- IOS app启动过程
1.main函数 2.UIApplicationMain * 创建UIApplication对象 * 创建UIApplication的delegate对象 3.delegate对象开始处理(监 ...
- 20151203--filter
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/htm ...