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

精简后,就其实一点,只要有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 = 2;
//抗锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
//渐变填充
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
//画尖角
if (cusp)
{
span = 10;
PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
PointF[] ptsArray = { p1, p2, p3 };
g.FillPolygon(myLinearGradientBrush, ptsArray);
}
//填充
g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height-1, _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, 180, 90);
gp.AddArc(width - radius, y, radius, radius, 270, 90);
gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
gp.AddArc(x, height - radius, radius, radius, 90, 90);
gp.CloseAllFigures();
return gp;
} private void panel1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, 18,true, Color.FromArgb(90, 143, 0), Color.FromArgb(41, 67, 0));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个Panel", new Font("微软雅黑", 9, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
} private void panel2_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, 18, false, Color.FromArgb(113, 113, 113), Color.FromArgb(0, 0, 0));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个Panel", new Font("微软雅黑", 9, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
} private void button1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, 18, false, Color.FromArgb(0, 122, 204), Color.FromArgb(8, 39, 57));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个按钮", new Font("微软雅黑", 9, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
} private void label1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, 18, false, Color.FromArgb(210, 210, 210), Color.FromArgb(242, 242, 242));
base.OnPaint(e); Graphics g = e.Graphics;
g.DrawString("其实我是Label", new Font("微软雅黑", 9, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(10, 10));
}
}
}

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个角还有颜色。

皆可画圆。

winfrom控件圆角的更多相关文章

  1. <iOS小技巧>UIview指定设置控件圆角

      一.用法:   众所周知,设置控件的圆角使用layer.cornerRadius属性即可,但是这样设置成的结果是4个边角都是圆角类型.   利用班赛尔曲线画角:   //利用班赛尔曲线画角 UIB ...

  2. WPF 精修篇 WPF嵌入Winfrom控件

    原文:WPF 精修篇 WPF嵌入Winfrom控件 先增加DLL 支持 使用  WindowsFormsHost 来加载Forms的控件 引用命名空间 xmlns:forms="clr-na ...

  3. Winfrom控件 特效

    链接:https://pan.baidu.com/s/1O9e7sxnYFYWD55Vh5fxFQg 提取码:5cey 复制这段内容后打开百度网盘手机App,操作更方便哦 Winfrom控件查询手册. ...

  4. C#winfrom控件命名规范

     ※用红字标记的部分表示有重复出现,括号内为替代表示方案 1.标准控件 序号 控件类型简写 控件类型 1 btn Button 2 chk CheckBox 3 ckl CheckedListBox ...

  5. Winfrom控件使用

    1.Lablelable添加图片,解决图片和字体重叠? Text属性添加足够空格即可,显示效果如下所示: 2.根据窗体名称获取窗体并显示到指定panel? Label item = sender as ...

  6. winfrom控件——基本工具

    窗体事件:属性—事件—load(双击添加) 窗体加载完之后的事件: 删除事件:先将属性事件里挂号的事件名删掉(行为里的load)再删后台代码里的事件. 控件:工具箱里(搜索—双击或点击拖动到窗体界面) ...

  7. 调整Winfrom控件WebBrowser的默认浏览器内核版本

    一.问题解析: 今天在调试程序的时候,需要使用C#的客户端远程登录一个Web页面,用到了WebBrowser控件.但是却发现了一件很神奇的事情:当前浏览器使用的内核,可以通过访问下面这个网站获取:ht ...

  8. Android中实现控件圆角边框

    首先,在drawable文件夹下新建一个xml文件: <?xml version="1.0" encoding="utf-8"?> <shap ...

  9. iOS控件圆角与半圆角

    开发过程中难免用到圆角以及恶心的半圆角,看代码 半圆角:这是把左边的两个角切成了圆角 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoun ...

随机推荐

  1. python3.4+Django+pymysql

    pip install Pymysql 修改app里面的__init__.py import pymysqlpymysql.install_as_MySQLdb()

  2. 如何编译生成 mkfs.ubifs、ubinize 工具

    参考文档: 1.<CoM335X linux开发指南.pdf>的附件1 2.ubifs的制作,移植的重点详解(使用交叉编译器) 3.UBIFS文件系统简介 与 利用mkfs.ubifs和u ...

  3. WebSocket的简单实现&jsp

    创建一个web项目 导入依赖: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=& ...

  4. 最短路———Floyd算法

    C - 六度分离 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  5. 吴裕雄--天生自然MySQL学习笔记:MySQL 连接的使用

    使用 MySQL 的 JOIN 在两个或多个表中查询数据. 可以在 SELECT, UPDATE 和 DELETE 语句中使用 Mysql 的 JOIN 来联合多表查询. JOIN 按照功能大致分为如 ...

  6. Tensorflow基础笔记

    1.Keras是一个由Python编写的开源人工神经网络库. 2.深度学习主要应用在三个大的方向,计算机视觉,自然语言处理,强化学习 3.计算机视觉主要有:图片识别,目标检测,语义分割,视频理解(行为 ...

  7. matlab中画一条折线时怎样显示出每个点折点的数值

    举个例子: num=[5,44,62,154,264,365,398,480,619,705,762,728,669,726,890,731,707,696,558,509,444];date=[1. ...

  8. 可能对Flutter应用程序开发有用的代码/库/专有技术列表

    当我开始使用Flutter实施该应用程序时,我开始担心“如何最好地编写?”以及“如何使其更好地放置?”. 在这种情况下,您将需要参考GitHub上发布的代码和应用程​​序. 因此,我收集了似乎对Flu ...

  9. 史上最难PHPer笔试题,40分就能月薪过万!附答案

    请批判性的学习,欢迎大牛指正错误 1.有关PHP字符串的说法,不对的是:A.如果一个脚本的编码是 ISO-8859-1,则其中的字符串也会被编码为 ISO-8859-1.B.PHP的字符串在内部是字节 ...

  10. python学习笔记-函数与可变长参数

    一.函数 1. def test(x): y=x+1 return yprint(test) #这是打印函数在内存中的地址 过程:就是没有返回值的函数 在python中过程也是函数,就算没哟返回值,也 ...