刚好用到这个功能,看了好些例子。我就不明白,简单的一个事,一些文章里的代码写的那个长啊,还让人看么。

精简后,就其实一点,只要有paint事件的组件,都可画圆角,没有的外面套一个panel就行了。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Gid_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
{
int span = ;
//抗锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
//渐变填充
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
//画尖角
if (cusp)
{
span = ;
PointF p1 = new PointF(rectangle.Width - , rectangle.Y + );
PointF p2 = new PointF(rectangle.Width - , rectangle.Y + );
PointF p3 = new PointF(rectangle.Width, rectangle.Y + );
PointF[] ptsArray = { p1, p2, p3 };
g.FillPolygon(myLinearGradientBrush, ptsArray);
}
//填充
g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height-, _radius));
}
public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
{
//四边圆角
GraphicsPath gp = new GraphicsPath();
gp.AddArc(x, y, radius, radius, , );
gp.AddArc(width - radius, y, radius, radius, , );
gp.AddArc(width - radius, height - radius, radius, radius, , );
gp.AddArc(x, height - radius, radius, radius, , );
gp.CloseAllFigures();
return gp;
} private void panel1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, ,true, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个Panel", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.White), new PointF(, ));
} private void panel2_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, , false, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个Panel", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.White), new PointF(, ));
} private void button1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, , false, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个按钮", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.White), new PointF(, ));
} private void label1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, , false, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e); Graphics g = e.Graphics;
g.DrawString("其实我是Label", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.Black), new PointF(, ));
}
}
}

int _radius 圆的度数

bool cusp 画不画尖角

Color begin_color, Color end_color 渐变色的起始和结束颜色

private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
        {.......}

圆角按钮要设置

否则4个角还有颜色。

皆可画圆。

初学c# -- 学习笔记(六) winfrom组件圆角的更多相关文章

  1. Spring Boot 学习笔记(六) 整合 RESTful 参数传递

    Spring Boot 学习笔记 源码地址 Spring Boot 学习笔记(一) hello world Spring Boot 学习笔记(二) 整合 log4j2 Spring Boot 学习笔记 ...

  2. 初学c# -- 学习笔记(一)

    初学c# -- 学习笔记(一) 学习C#了,参考许多资料,一步步学习.这一段学习ajax的工作原理,参照其他例子写了web版的群聊小程序,全部文件代码也就不到300行,很简单.使用时先输入用户名,点确 ...

  3. java之jvm学习笔记六-十二(实践写自己的安全管理器)(jar包的代码认证和签名) (实践对jar包的代码签名) (策略文件)(策略和保护域) (访问控制器) (访问控制器的栈校验机制) (jvm基本结构)

    java之jvm学习笔记六(实践写自己的安全管理器) 安全管理器SecurityManager里设计的内容实在是非常的庞大,它的核心方法就是checkPerssiom这个方法里又调用 AccessCo ...

  4. Learning ROS for Robotics Programming Second Edition学习笔记(六) indigo xtion pro live

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...

  5. Typescript 学习笔记六:接口

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  6. python3.4学习笔记(六) 常用快捷键使用技巧,持续更新

    python3.4学习笔记(六) 常用快捷键使用技巧,持续更新 安装IDLE后鼠标右键点击*.py 文件,可以看到Edit with IDLE 选择这个可以直接打开编辑器.IDLE默认不能显示行号,使 ...

  7. Go语言学习笔记六: 循环语句

    Go语言学习笔记六: 循环语句 今天学了一个格式化代码的命令:gofmt -w chapter6.go for循环 for循环有3种形式: for init; condition; increment ...

  8. 【opencv学习笔记六】图像的ROI区域选择与复制

    图像的数据量还是比较大的,对整张图片进行处理会影响我们的处理效率,因此常常只对图像中我们需要的部分进行处理,也就是感兴趣区域ROI.今天我们来看一下如何设置图像的感兴趣区域ROI.以及对ROI区域图像 ...

  9. Linux学习笔记(六) 进程管理

    1.进程基础 当输入一个命令时,shell 会同时启动一个进程,这种任务与进程分离的方式是 Linux 系统上重要的概念 每个执行的任务都称为进程,在每个进程启动时,系统都会给它指定一个唯一的 ID, ...

  10. 【React】react学习笔记02-面向组件编程

    react学习笔记02-面向组件编程 面向组件编程,直白来说,就是定义组件,使用组件. 以下内容则简单介绍下组建的声明与使用,直接复制demo观测结果即可. 步骤: 1.定义组件   a.轻量组件-函 ...

随机推荐

  1. js实现的点击div区域外隐藏div区域(转)

    首先看下JS的事件模型,JS事件模型为向上冒泡,如onclick事件在某一DOM元素被触发后,事件将跟随节点向上传播,直到有click事件绑定在某一父节点上,如果没有将直至文档的根. 阻止冒泡: 1. ...

  2. [转]安装SharePoint 2013时安装AppFabric失败(错误码:1603)

    转自:http://blogs.technet.com/b/praveenh/archive/2013/02/22/sharepoint-2013-prerequisites-fails-with-m ...

  3. W5200移植W5500驱动教程

    说明,移植例程为我按照这个教程移植的例程,测试通过.工程模板为我经常使用的一个w5500模板,可以在里面直接添加文件编程.1. 将driver文件夹中W5500文件夹和所有.c文件复制到工程/sour ...

  4. Access数据库的模糊查询到底是用*还是%

    今天被用了一下Access数据库,结果被它的模糊查询给折腾了一上午,到底是用*还是%?特此记下来 事情是这样的,我用C#写了个小的窗体程序,访问Access数据库进行一个模糊查询,我先手工往Acces ...

  5. 最新原创:Power8伴随云计算横空出世

    Power8伴随云计算横空出世 自从IBM将并不赚钱的x86服务器业务转手给联想之后,从此IBM便开始了硬件转型的新里程碑.伴随此事继续发酵的还有Power System Linux落户北京,从此IB ...

  6. IIS7 启用GZip压缩

    GZip压缩通常会达到70%以上的压缩率,如果是手机Web这无疑会使网站的访问速度大大增加,无论是CSS合并.JS合并.图片合并都不如GZip压缩来得简单直接.如果一个网页是100K,那么启用GZip ...

  7. C#对DBF文件的操作

    protected void Page_Load(object sender, EventArgs e) { System.Data.Odbc.OdbcConnection conn = new Sy ...

  8. 一个简单的 MVVM 实现

    简介 一个简单的带有双向绑定的 MVVM 实现. 例子 使用 新建一个 ViewModel 对象, 参数分别为 DOM 元素以及绑定的数据即可. 指令 本 MVVM 的指令使用 data 数据, 即 ...

  9. tomcat7/8 启用调试模式,可进行远程调试

    tomcat7,和 tomcat6 的jpda 不一样,tomcat7已经把jpda配置的属性在catalina.sh/catalina.bat里面已经写好了,我们不需要向tomcat6那样去设置参数 ...

  10. 答:SQLServer DBA 三十问之三:有哪些操作会使用到TempDB;如果TempDB异常变大,可能的原因是什么,该如何处理

    3. 有哪些操作会使用到TempDB:如果TempDB异常变大,可能的原因是什么,该如何处理: tempdb的用途:1)存储专用和全局临时变量,不考虑数据库上下文: 2)与Order by 子句,游标 ...