【原创】重绘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.这个伸缩控件分为两个部分,头部是一个自定义组件,伸缩控件的背景为灰色,头部背景要求白色.伸缩控件在点击按钮时会重绘,同时他内部的控件也会重绘 ...
随机推荐
- 在mangento后台调用wysiwyg编辑器
在mangento后台调用操蛋的wysiwyg编辑器: 1.在头部加载TincyMCE protected function _prepareLayout() { parent::_prepa ...
- Winform mschart 动态绑定X时间表
效果图: 代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...
- C#:让控件TextBox的滚动条保持在最下方
//该事件让TextBox控件的滚动条始终保持在最下方 private void TextBox_TextChanged(object sender, EventArgs e) ...
- c#导出文件,文件名中文乱码解决方法。
public string clFielName(string fileName) { System.Web.HttpContext curContext = System.Web.HttpConte ...
- HttpServletRequest 各种方法总结(转自百度经验)
HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,开发人员通过这个对象的方法,可以获得客户这些信息. req ...
- leetcode Binary Tree Inorder Traversal python
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...
- 【JQ成长笔记】jQuery Validate验证插件
validate是一款很好的jq插件,提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同 ...
- 学习zepto.js(原型方法)
学习zepto.js(原型方法)[1] 转载 新的一周,新的开始,今天来学习一下zepto里边的原型方法,就是通过$.进行调用的方法,也是可以通过$.fn进行扩展的方法: $.camelCase(): ...
- Javascript 匀速运动停止条件——逐行分析代码,让你轻松了解运动的原理
我们先来看下之前的匀速运动的代码,修改了速度speed后会出现怎么样的一个bug.这里加了两个标杆用于测试 <style type="text/css"> #div1 ...
- SQL Server 修改表
alter table 可能用三种方式来完成. 第一种: 只修改元数据. 1.删除一个列. 2.一个行被增加而且空值被认为是所有行的新值. 3.当可变长度的列的长度增加时. 4.不允许为空的列被允许为 ...