WinForm绘制圆角的方法
作者:我心依旧 时间:2023-06-21 14:23:51
本文实例讲述了WinForm绘制圆角的方法。分享给大家供大家参考。具体实现方法如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
namespace AppStartSample
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
public void SetWindowRegion()
{
System.Drawing.Drawing2D.GraphicsPath FormPath;
FormPath = new System.Drawing.Drawing2D.GraphicsPath();
Rectangle rect = new Rectangle(0, 22, this.Width, this.Height - 22);//
FormPath = GetRoundedRectPath(rect, 30);
this.Region = new Region(FormPath);
}
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
{
int diameter = radius;
Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
GraphicsPath path = new GraphicsPath();
// 左上角
path.AddArc(arcRect, 180, 90);
// 右上角
arcRect.X = rect.Right - diameter;
path.AddArc(arcRect, 270, 90);
// 右下角
arcRect.Y = rect.Bottom - 0;
path.AddArc(arcRect, 0, 90);
// 左下角
arcRect.X = rect.Left;
path.AddArc(arcRect, 90, 90);
path.CloseFigure();
return path;
}
protected override void OnResize(System.EventArgs e)
{
this.Region = null;
SetWindowRegion();
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
标签:WinForm,绘制,圆角
0
投稿
猜你喜欢
Java简单实现约瑟夫环算法示例
2023-04-04 09:59:41
android开发环境遇到adt无法启动的问题分析及解决方法
2023-12-11 13:13:23
Spark SQL关于性能调优选项详解
2021-11-05 22:32:56
基于Springboot实现JWT认证的示例代码
2023-04-01 09:46:40
springboot整合shiro实现记住我功能
2023-07-29 20:21:34
Java将字符串转化为数组的两种方法
2021-07-07 20:33:49
Android 检测键盘显示或隐藏键盘的实现代码
2022-09-08 09:14:05
android实现背景音乐播放功能
2023-09-17 23:29:25
Android开发实现popupWindow弹出窗口自定义布局与位置控制方法
2022-10-13 11:42:09
Java中常见的陷阱题及答案
2021-08-10 16:32:11
unity3D实现摄像机抖动特效
2022-09-20 12:10:42
Spring Security实现基于角色的访问控制框架
2022-03-19 05:40:53
Spring Boot示例代码整合Redis详解
2022-03-20 19:23:37
Android编程实现添加低电流提醒功能的方法
2023-03-16 19:31:29
Java中如何快速构建项目脚手架的实现
2023-10-30 03:37:50
Android ListView 实现上拉加载的示例代码
2021-09-16 18:04:17
C/C++混合编程之extern “C”的使用示例
2021-11-18 03:33:58
Java下利用Jackson进行JSON解析和序列化示例
2023-09-27 14:37:38
Android 基于百度语音的语音交互功能(推荐)
2021-08-22 01:26:38
Android通过aapt命令获取apk详细信息(包括:文件包名,版本号,SDK等信息)
2023-11-01 11:29:19