winfrom控件圆角
刚好用到这个功能,看了好些例子。我就不明白,简单的一个事,一些文章里的代码写的那个长啊,还让人看么。
精简后,就其实一点,只要有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控件圆角的更多相关文章
- <iOS小技巧>UIview指定设置控件圆角
一.用法: 众所周知,设置控件的圆角使用layer.cornerRadius属性即可,但是这样设置成的结果是4个边角都是圆角类型. 利用班赛尔曲线画角: //利用班赛尔曲线画角 UIB ...
- WPF 精修篇 WPF嵌入Winfrom控件
原文:WPF 精修篇 WPF嵌入Winfrom控件 先增加DLL 支持 使用 WindowsFormsHost 来加载Forms的控件 引用命名空间 xmlns:forms="clr-na ...
- Winfrom控件 特效
链接:https://pan.baidu.com/s/1O9e7sxnYFYWD55Vh5fxFQg 提取码:5cey 复制这段内容后打开百度网盘手机App,操作更方便哦 Winfrom控件查询手册. ...
- C#winfrom控件命名规范
※用红字标记的部分表示有重复出现,括号内为替代表示方案 1.标准控件 序号 控件类型简写 控件类型 1 btn Button 2 chk CheckBox 3 ckl CheckedListBox ...
- Winfrom控件使用
1.Lablelable添加图片,解决图片和字体重叠? Text属性添加足够空格即可,显示效果如下所示: 2.根据窗体名称获取窗体并显示到指定panel? Label item = sender as ...
- winfrom控件——基本工具
窗体事件:属性—事件—load(双击添加) 窗体加载完之后的事件: 删除事件:先将属性事件里挂号的事件名删掉(行为里的load)再删后台代码里的事件. 控件:工具箱里(搜索—双击或点击拖动到窗体界面) ...
- 调整Winfrom控件WebBrowser的默认浏览器内核版本
一.问题解析: 今天在调试程序的时候,需要使用C#的客户端远程登录一个Web页面,用到了WebBrowser控件.但是却发现了一件很神奇的事情:当前浏览器使用的内核,可以通过访问下面这个网站获取:ht ...
- Android中实现控件圆角边框
首先,在drawable文件夹下新建一个xml文件: <?xml version="1.0" encoding="utf-8"?> <shap ...
- iOS控件圆角与半圆角
开发过程中难免用到圆角以及恶心的半圆角,看代码 半圆角:这是把左边的两个角切成了圆角 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoun ...
随机推荐
- POJ 1159:Palindrome 最长公共子序列
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 56273 Accepted: 19455 Desc ...
- Java算法练习——无重复字符的最长子串
题目链接 题目描述 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 &qu ...
- Maven:程序包不存在,找不到符号
maven build时出现了以下的错误: 程序包xx.xx不存在,xxx找不到符号 原因一:DAO层依赖Service接口层的Bean类,在pom.xml中添加了对Service的依赖,也因此引入了 ...
- JAVA初学者——Hello,World!
大家好,我是浩宇大熊猫 我本科专业学的是GIS(Geographical Information System),大学期间也学习了很多的编程语言,有C/C++/JAVA等 之前给我们授课的是韩冰老师, ...
- opencv显示图像
使用imshow函数 imshow函数功能 imshow的函数功能也非常简单,名称也可以看出来,image show的缩写.imshow负责的就是将图片显示在窗口中,通过设备屏幕展现出来.与imrea ...
- 调度算法FCFS、SJF和优先权调度的介绍和例题
调度算法 一.先来先服务FCFS (First Come First Serve) 1.思想: 选择最先进入后备/就绪队列的作业/进程,入主存/分配CPU 2.优缺点 优点:对所有作业/进程公平,算法 ...
- Luogu P3031 高于中位数
定义序列\(x_i = f([H_i >=x])\;\;\;\;其中f(0) = -1,f(1) = 1\),那么区间[i,j]满足条件当且仅当sum_j-sum_{i-1} > 0,即s ...
- 计算机网络(2): http的基础上用SSL或TSL加密
加密过程具体TCP实现 步骤 1 : 客户端通过发送Client Hello报文开始SSL通信(这里是在TCP的三次握手已经完成的基础上进行的).报文中包含客户端支持的SSL的指定版本.加密组件列表( ...
- 题解 P1884 【[USACO12FEB]过度种植(银)Overplanting 】
什么,扫描线需要线段树? 那我第一个不干啊(其实是不会写) 这里介绍一种裸的扫描线: 我们根据x排序,对于相等的 \(x\) ,将 \(y\) 进入和退出分类讨论,然后全部放进set里面.每次 \(x ...
- git 推送到github最常用命令
初始化仓库,上传到github中. git init git add README.md git commit -m "first commit" git remote add o ...