c#winform如何画圆角控件,看完这篇文章你就会了

在我们日常工作开发中,可能会经常为了让控件更加好看,对控件进行圆角处理,有时候还有可能对四个角设置不同的圆角,那么我们改怎么样做呢?楼主封装了一个类,绝对的项目实战使用,现在分享给你们

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace cloudproject.untils
{
    public class UoperaGraphics
    {

        /// <summary>
        /// 圆角矩形边框
        /// </summary>
        /// <param name="rectangle">原始矩形</param>
        /// <param name="g">Graphics 对象</param>
        /// <param name="radius">圆角半径</param>
        /// <param name="backColor">颜色</param>
        public static void FrameRoundRectangle(Rectangle rectangle, Graphics g, int radius, Color backColor)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            if (radius == 0)
            {
                g.DrawRectangle(new Pen(backColor), rectangle);
            }
            else
            {
                g.DrawPath(new Pen(backColor), DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - 2, rectangle.Height - 1, radius));
            }
        }
        /// <summary>
        /// 圆角边框【可设置四个角不同的圆角】
        /// </summary>
        /// <param name="rectangle">控件的范围</param>
        /// <param name="g">g</param>
        /// <param name="top_left_radius">左上角的圆角</param>
        /// <param name="top_right_radius">右上角的圆角</param>
        /// <param name="bottom_left_radius">底部左边的圆角</param>
        /// <param name="bottom_right_radius">底部右边的圆角</param>
        /// <param name="backColor">要描述的边框的背景的颜色</param>
        public static void FrameRoundRectangle_Four(Rectangle rectangle, Graphics g, int top_left_radius, int top_right_radius, int bottom_left_radius, int bottom_right_radius, Color backColor)
        {

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            if (top_left_radius == 0)
            {
                g.DrawRectangle(new Pen(backColor), rectangle);
            }
            else
            {
                g.DrawPath(new Pen(backColor), DrawRoundRect_four(rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1, top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius));
            }
        }
        /// <summary>
        /// 圆角矩形
        /// </summary>
        /// <param name="rectangle">原始矩形</param>
        /// <param name="g">Graphics 对象</param>
        /// <param name="radius">圆角半径</param>
        /// <param name="backColor">颜色</param>
        public static void FillRoundRectangle(Rectangle rectangle, Graphics g, int radius, Color backColor)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            if (radius == 0)
            {
                g.FillRectangle(new SolidBrush(backColor), rectangle);
            }
            else
            {
                g.FillPath(new SolidBrush(backColor), DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - 2, rectangle.Height - 1, radius));
            }
        }

        /// <summary>
        /// 圆角矩形粗边框
        /// </summary>
        public static void FrameBoldRoundRectangle(Rectangle rectangle, Graphics g, int radius, Color backColor, int linewide)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            if (radius == 0)
            {
                g.DrawRectangle(new Pen(backColor, linewide), rectangle);
            }
            else
            {
                g.DrawPath(new Pen(backColor, linewide), DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - 2, 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(x + width - radius, y, radius, radius, 270, 90);
            gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90);
            gp.AddArc(x, y + height - radius, radius, radius, 90, 90);
            gp.CloseAllFigures();
            return gp;
        }
        public static void FillRoundRectangle_four(Rectangle rectangle, Graphics g, int radius_topleft, int radius_topright, int radius_bottom_left, int radius_bottomright, Color backColor)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            if (radius_topleft == 0)
            {
                g.FillRectangle(new SolidBrush(backColor), rectangle);
            }
            else
            {
                g.FillPath(new SolidBrush(backColor), DrawRoundRect_four(rectangle.X, rectangle.Y, rectangle.Width - 2, rectangle.Height - 1, radius_topleft, radius_topright, radius_bottom_left, radius_bottomright));
            }
        }
        public static GraphicsPath DrawRoundRect_four(int x, int y, int width, int height, int radius_topleft, int radius_topright, int radius_bottomleft, int radius_bottomright)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddArc(x, y, radius_topleft, radius_topleft, 180, 90);
            gp.AddArc(x + width - radius_topright, y, radius_topright, radius_topright, 270, 90);
            gp.AddArc(x + width - radius_bottomleft, y + height - radius_bottomleft, radius_bottomleft, radius_bottomleft, 0, 90);
            gp.AddArc(x, y + height - radius_bottomright, radius_bottomright, radius_bottomright, 90, 90);
            gp.CloseAllFigures();
            return gp;
        }
    }
}

如果有需要可以直接粘贴复制使用,我自己的项目在用哦!

智能网联汽车的安全员高级考试涉及多个方面的专业知识,包括但不限于自动驾驶技术原理、车辆传感器融合、网络安全防护以及法律法规等内容。以下是针对该主题的一些核心知识解析: ### 关于智能网联车安全员高级考试的核心内容 #### 1. 自动驾驶分级标准 国际自动机工程师学会(SAE International)定义了六个级别的自动驾驶等级,从L0到L5[^1]。其中,L3及以上级别需要安全员具备更高的应急处理能力。 #### 2. 车辆感知系统的组成与功能 智能网联车通常配备多种传感器,如激光雷达、毫米波雷达、摄像头和超声波传感器等。这些设备协同工作以实现环境感知、障碍物检测等功能[^2]。 #### 3. 数据通信与网络安全 智能网联车依赖V2X(Vehicle-to-Everything)技术进行数据交换,在此过程中需防范潜在的网络攻击风险,例如中间人攻击或恶意软件入侵[^3]。 #### 4. 法律法规要求 不同国家和地区对于无人驾驶测试及运营有着严格的规定,考生应熟悉当地交通法典中有关自动化驾驶部分的具体条款[^4]。 ```python # 示例代码:模拟简单决策逻辑 def decide_action(sensor_data): if sensor_data['obstacle'] and not sensor_data['emergency']: return 'slow_down' elif sensor_data['pedestrian_crossing']: return 'stop_and_yield' else: return 'continue_driving' example_input = {'obstacle': True, 'emergency': False, 'pedestrian_crossing': False} action = decide_action(example_input) print(f"Action to take: {action}") ``` 需要注意的是,“同学”作为特定平台上的学习资源名称,并不提供官方认证的标准答案集;建议通过正规渠道获取教材并参加培训课程来准备此类资格认证考试
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

搬砖大师兄.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值