【原创】重绘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.这个伸缩控件分为两个部分,头部是一个自定义组件,伸缩控件的背景为灰色,头部背景要求白色.伸缩控件在点击按钮时会重绘,同时他内部的控件也会重绘 ...
随机推荐
- aix Mysql-Rpm puppet puppetAgent
http://www.bullfreeware.com/toolbox.php (Large Open Source Software Archieve for AIX 提供MySQL5.1 fo ...
- kubuntu添加windows字体
1.选取字体 在/usr/share/fonts/truetype中新建一个目录,命名为ms,然后将Windows\fonts 目录下的tahoma.ttf.tahomabd.ttf(Tahoma的粗 ...
- java实现xml文件增删改查
java一次删除xml多个节点: 方案1.你直接改动了nodeList,这一般在做循环时是不同意直接这么做的. 你能够尝试在遍历一个list时,在循环体同一时候删除list里的内容,你会得到一个异常. ...
- 【玩转Ubuntu】01. Ubuntu上配置JDK
一.安装JDK 提示:这里我们使用jdk1.6,因为android开发要求使用1.6.如果不信你可以打开android studio,它会提示你选择JDK6的路径 下载地址: http://www.o ...
- Oracle初级入门 根据某字段重复只取一条记录,并计计算重复条数
在平常开发中,去重复数据经常使用到,本人新手,接触Oracle也不久,开发中用到的小知识点,记录一下,老鸟可绕道,如果有写错的,请指正. 去重复记录可以使用distinct,当只查询一列数据时,可以轻 ...
- PHP自学4——通过mail函数将feedback界面用户填写表单信息发送至指定邮箱
这一讲的内容依旧简单(谁叫PO主水平菜,依旧是个弱鸡ORZ),通过PHP的内置mail函数将一个反馈界面的信息发送到指定邮箱.在Windows平台不能直接需要使用该函数,需要下载一个sendmail并 ...
- VMware vSphere Client为虚拟机制定物理网卡(图文并茂)
1.首先,查看我的服务器有几张网卡,如下图共3张,接下来我将为虚拟主机制定一张网卡,以及为当中的两台虚拟的CentOS7各制定一张网卡. 2.打开“硬件”---->“网络”,如图,已经启用一张网 ...
- 用正则表达式替换内容 php
以前做一个项目,就是有一个问答的页面,比如说在回答或者提问的内容中插入表情.写到内容里的是表情图片的名字(而且是不带后缀的,比如:f_002.png)表情包放在项目里,我需要在取除内容的时候将里面的表 ...
- SQLServer 中实现类似MySQL中的group_concat函数的功能
SQLServer中没有MySQL中的group_concat函数,可以把分组的数据连接在一起. 后在网上查找,找到了可以实现此功能的方法,特此记录下. SELECT a, stuff((SELECT ...
- sersync+inotify实时备份数据
Sersync项目简介与框架 简介 Sersync项目利用inotify与rsync技术实现对服务器数据实时同步的解决方案,其中inotify用于监控sersync所在服务器上文件系统的事件变化,rs ...