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

你可能感兴趣的文章
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
node exporter完整版
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
查看>>
Node 裁切图片的方法
查看>>
Node+Express连接mysql实现增删改查
查看>>
node, nvm, npm,pnpm,以前简单的前端环境为什么越来越复杂
查看>>
Node-RED中Button按钮组件和TextInput文字输入组件的使用
查看>>
Node-RED中Switch开关和Dropdown选择组件的使用
查看>>