博客
关于我
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/

你可能感兴趣的文章
numpy数组替换其中的值(如1替换为255)
查看>>
numpy数组索引-ChatGPT4o作答
查看>>
NUMPY矢量化np.prod不能构造具有超过32个操作数的ufunc
查看>>
Numpy矩阵与通用函数
查看>>
numpy绘制热力图
查看>>
numpy转PIL 报错TypeError: Cannot handle this data type
查看>>
Nutch + solr 这个配合不错哦
查看>>
NutzCodeInsight 2.0.7 发布,为 nutz-sqltpl 提供友好的 ide 支持
查看>>
NutzWk 5.1.5 发布,Java 微服务分布式开发框架
查看>>
NUUO网络视频录像机 css_parser.php 任意文件读取漏洞复现
查看>>
NuxtJS 接口转发详解:Nitro 的用法与注意事项
查看>>
NVelocity标签使用详解
查看>>
Nvidia Cudatoolkit 与 Conda Cudatoolkit
查看>>
NVIDIA GPU 的状态信息输出,由 `nvidia-smi` 命令生成
查看>>
NVIDIA-cuda-cudnn下载地址
查看>>
nvidia-htop 使用教程
查看>>
nvidia-smi 参数详解
查看>>
nvm安装以后,node -v npm 等命令提示不是内部或外部命令 node多版本控制管理 node多版本随意切换
查看>>
NYOJ 1066 CO-PRIME(数论)
查看>>
nyoj------203三国志
查看>>