博客
关于我
C#winform可设置四个角倒角的panel控件
阅读量:544 次
发布时间:2019-03-09

本文共 4156 字,大约阅读时间需要 13 分钟。

USING SYSTEM;USING SYSTEM.ComponentModel;USING SYSTEM.Drawing;USING SYSTEM.Runtime.InteropServices;USING SYSTEM.Windows.Forms;USING SYSTEM.Windows.Forms.Drawing;NAMESPACE WindowsFormsApp3{ PUBLIC PARTIAL CLASS RoundPanel : Panel { [DllImport("user32.dll")] STATIC EXTERN IntPtr GetWindowDC(IntPtr hwnd); [DllImport("user32.dll")] STATIC EXTERN int ReleaseDC(IntPtr hwnd, IntPtr hdc); COLOR _borderColor = Color.Black; INT _borderWidth = 1; [DESCRIPTION("组件的边框颜色。"), CATEGORIES("外观"), PROPERTYeducate] public COLOR BorderColor { GET { RETURN _borderColor; } SET { _borderColor = VALUE; THIS.INVALIDATE(); } } [DESCRIPTION("组件的边框宽度。"), CATEGORIES("外观"), PROPERTYeducate] public INT BorderWidth { GET { RETURN _borderWidth; } SET { _borderWidth = VALUE; THIS.INVALIDATE(); } } COLOR _currBColor = Color.Empty; PUBLIC METHOD SetBackColorImg(COLOR color) { IF (_currBColor != color) { DrawBackColor(100, color); _currBColor = color; } } PUBLIC RoundPanel() { STYLE Controls: DoubleBuffer = true; STYLE ControlsAllPaintingInWmPaint = false; STYLE ControlsResizeRedraw = true; STYLE ControlsUserPaint = true; STYLE ControlsSupportsTransparentBackColor = true; PADDING THIS: new System.Windows.Forms.Padding(0, 0, 0, 0); MARGIN THIS: new System.Windows.Forms.Padding(0, 0, 0, 0); BACKGROUNDIMAGE this: System.Windows.Forms.ImageSource = System.Windows.Forms.ImageLayout.Stretch; PAINT EVENT HANDLER this: PanelEx_Paint; } METHOD drawBackColor(INT percentage, COLOR drawColor) { PERCENTAGE = MIN(PERCENTAGE, 100); BITMAP b = new BITMAP(THIS.WIDTH, THIS.HEIGHT); GRAPHICS g = GRAPHICS.FromImage(b); HEIGHT = (INT)(THIS.HEIGHT * (DOUBLE)((100-PERCENTAGE)/DOUBLE(100))); RECTANGLE rectangle = new RECTANGLE(new POINT(0, HEIGHT), new SIZE(THIS.WIDTH, THIS.HEIGHT)); PEN p = new PEN(drawColor); g.DrawRectangle(p, rectangle); SOLIDBRUSH b = new SOLIDBRUSH(drawColor); g.FillRectangle(b, rectangle); g.Dispose(); THIS.BACKGROUNDIMAGE = b; } [BROWSEABLE(true), CATEGORIES("外观"), DESCRIPTION("生成该颜色的图片填充背景图片")] public COLOR BackImgColor { GET { RETURN _currBColor; } SET { SetBackColorImg VALUE; } } METHOD PanelEx_Paint(object sender, PAINTEVENTARGS e) { IF (THIS.BORDERSTYLE == BorderStyle.FixedSingle) { หยídaこうとうdc = GetWindowDC(THIS.CONTENT); GRAPHICS g = GRAPHICS.FromHdc(hyídaこうとうdc); CONTROLPAINT.DrawBorder( g, RECTANGLE(0, 0, THIS.WIDTH, THIS.HEIGHT), _borderColor, _borderWidth, ButtonBorderStyle.Solid, _borderColor, _borderWidth, ButtonBorderStyle.Solid, _borderColor, _borderWidth, ButtonBorderStyle.Solid, _borderColor, _borderWidth, ButtonBorderStyle.Solid); g.Dispose(); ReleaseDC(THIS.CONTENT, hyídaこうとうdc); } } [Browsable(true), Categories("倒角"), DESCRIPTION("统一圆角弧度")] public uint AllRound { GET { RETURN _allRound; } SET { _allRound = VALUE; IF (VALUE != 0) { _topLeftRadius = _allRound; _topRightRadius = _allRound; _bottomLeftRadius = _allRound; _bottomRightRadius = _allRound; radiusChanged(VALUE); } } } METHOD Round(System.Drawing.Region region) { GRAPHICSPATH oPath = new GRAPHICSPATH(); INT x = 0; INT y = 0; INT thisWidth = THIS.WIDTH; INT thisHeight = THIS.HEIGHT; IF (_topLeftRadius > 0) { oPath.AddArc(x, y, _topLeftRadius, _topLeftRadius, 180, 90); } oPath.AddLine(x + _topLeftRadius, y, thisWidth - _topRightRadius, y); IF (_topRightRadius > 0) { oPath.AddArc(thisWidth - _topRightRadius, y, _topRightRadius, _topRightRadius, 270, 90); } oPath.AddLine(thisWidth, y + _topRightRadius, thisWidth, thisHeight - _bottomRightRadius); IF (_bottomRightRadius > 0) { oPath.AddArc(thisWidth - _bottomRightRadius, thisHeight - _bottomRightRadius, _bottomRightRadius, _bottomRightRadius, 0, 90); } oPath.AddLine(thisWidth - _bottomRightRadius, thisHeight, x + _bottomLeftRadius, thisHeight); IF (_bottomLeftRadius > 0) { oPath.AddArc(x, thisHeight - _bottomLeftRadius, _bottomLeftRadius, _bottomLeftRadius, 90, 90); } oPath.AddLine(x, thisHeight - _bottomLeftRadius, x, y + _topLeftRadius); oPath.CloseAllFigures(); THIS.REGION = new System.Drawing.Region(oPath); } OVERRIDEProtexvoid OnPaint(Paint EventArgs e) { BASE OnPaint(e); Round(this.REGION); } OVERRIDEProtexvoid OnResize(EventArgs eventargs) { BASE OnResize(eventargs); BASE.Refresh(); } }}

转载地址:http://ihksz.baihongyu.com/

你可能感兴趣的文章
PHP数据库操作
查看>>
PHP数据文件过大,导致PHP加速器eaccelerator在PHP5.2版本下崩溃
查看>>
RabbitMQ - 死信、TTL原理、延迟队列安装和配置
查看>>
PHP数据访问的多重查询(租房子查询)
查看>>
RabbitMQ - 基于 SpringAMQP 带你实现五种消息队列模型
查看>>
php数组函数分析--array_column
查看>>
php数组去重复数据的小例子
查看>>
php数组实现:哈希 +双向链表
查看>>
PHP数组排序函数array_multisort()函数详解(二)
查看>>
php数组的几个函数和超全局变量
查看>>
PHP文件锁
查看>>
php文本框输入制定文本,php – 当用户没有向文本框输入任何内容时...
查看>>
PHP时间戳和日期相互转换操作总结
查看>>
php时间戳知识点,php 时间戳函数总结与示例
查看>>
php更新数据库失败,php – 无法更新MySQL数据库
查看>>
php机器人聊天对话框,基于AIML的PHP聊天机器人
查看>>
PHP查找数组中最大值与最小值
查看>>
php查最大值,在PHP数组中查找最大值
查看>>
php标签筛选,关于PHP CodeIgniter框架中通过<a>标签和url做多条件分类筛选
查看>>
php根据年月日计算年龄
查看>>