【原创】重绘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.这个伸缩控件分为两个部分,头部是一个自定义组件,伸缩控件的背景为灰色,头部背景要求白色.伸缩控件在点击按钮时会重绘,同时他内部的控件也会重绘 ...
随机推荐
- php技能考试每日一练
PHP技術者認定 1, [日本語文字のメール送信] (2016年10月31日)以下のコードは桃家タローさん宛てにメールを送るためのものである.コード内の[(1)]に入る正しいものを1つ次の記述の中から ...
- java web从零单排第十七期《struts2》数据标签库(1)
1.s:action标签: 此标签的作用是在JSP页面中访问action类的数据,执行某些操作,并返回相应的数据.其属性及意义如下: 属性名 是否必需 默认值 类型 说明介绍 executeResul ...
- .net通用权限框架B/S (五)--WEB(1)首页
通用权限框架--web 首页 1.首页截图 2.首页views 布局分为三部分top,left,main 引入easyui和jquery的js以及相关的css 使用easyui进行布局,分区代码bod ...
- Web-----》》》 一般处理程序 ashx
一般处理程序 后缀: 前台页面:.ashx 后台页面:.ashx.cs 打开方式:右键程序集--在浏览器中查看--输入url(如http://localhost:6560/firstAshx.ashx ...
- 望大神批评教育国庆无聊之作:ObjectValidator
起因: 本人国庆无聊,不知道干嘛, 所以模仿FluentValidation写了个简化版的ObjectValidator 个人设想是能用类似fluent的方式创建验证规则,然后使用者缓存并验证自己的对 ...
- flash Builder JSON使用实例
flash Builder JSON 使用说明(转载houdinime) XML虽然强大但有人觉得xml不够简洁,编码和解码也有一定难度,于是21世纪初有人发明了JSON编码,相比xml内容少并且容易 ...
- org.gradle.process.internal.ExecException:
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ...
- Html 笔记1
标题(Heading)是通过 <h1> - <h6> 等标签进行定义的. <h1>这是标题</h1> 段落是通过 <p> 标签进行定义的. ...
- 删除字符串中多余的空白字符和空行(C语言实现)
要求:处理一个字符串,删除字符串中多余的空格.水平制表符和空行,并满足下列要求: (1)对原字符串只能进行一次扫描.(2)不允许申请新的空间.(3)处理后的字符串的首尾不能有空格.制表符和空行.(4) ...
- 让vs2010的html编辑器验证html5语法
或者在Tools -> option -> Text Editor -> Html -> Validation