你的位置:首页-湖富奋香精有限公司 > 新闻资讯 >
new Size(_roundRadius
发布日期:2024-06-21 15:02 点击次数:159
媒介:不知说念从什么技能启动,群众心爱上了这种平滑式的缱绻,对于蓝本简纯粹单、方合法正的缱绻启动置之不睬了(我到当今还独爱Windows 8的缱绻);在Winform上作念出来这种平滑的后果相对来说依然比拟缺乏的,不像CSS一排代码就可措置。
对于圆角的代码思必好多东说念主皆用GDI+收场过,可是获胜的后果可能不太理思,大部分情况下皆有锯齿;其实对于纯色布景的情况下,这种锯齿依然不错消撤除的。
图片晒图机
底下是一段画图圆角的代码,可是这么获胜画图出来的话,就会产生锯齿
private void DrawRoundRegion() { Rectangle rect = new Rectangle(-1, -1, base.Width + 1, base.Height); Rectangle rect2 = new Rectangle(rect.Location, new Size(_roundRadius, _roundRadius)); GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddArc(rect2, 首页-新盛乌皮革有限公司 180f, 肇东市东亨净水器有限公司 90f);//左上角 rect2.X = rect.Right - _roundRadius; graphicsPath.AddArc(rect2,首页-湖康兴机场有限公司 270f, 90f);//右上角 rect2.Y = rect.Bottom - _roundRadius; rect2.Width += 1; rect2.Height += 1; graphicsPath.AddArc(rect2, 360f, 90f);//右下角 rect2.X = rect.Left; graphicsPath.AddArc(rect2,晒图机 90f, 90f);//左下角 graphicsPath.CloseFigure(); base.Region = new Region(graphicsPath); }
抛弃锯齿,对圆角区域进行填充
private void FillRoundRegion(Graphics graphics) { Rectangle rect = ClientRectangle; Rectangle rect2 = new Rectangle(rect.Location, new Size(_roundRadius, _roundRadius)); GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddArc(rect2, 180f, 90f);//左上角 rect2.X = rect.Right - _roundRadius - 1; graphicsPath.AddArc(rect2, 270f, 90f);//右上角 rect2.Y = rect.Bottom - _roundRadius - 1; graphicsPath.AddArc(rect2, 0f, 90f);//右下角 rect2.X = rect.Left; graphicsPath.AddArc(rect2, 90f, 90f);//左下角 graphicsPath.CloseFigure(); graphics.FillPath(new SolidBrush(HoverBackColor == Color.Empty ? _BackColor : HoverBackColor), graphicsPath); }
在Paint事件中进行调用
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; if (RoundRadius > 0) { DrawRoundRegion(); FillRoundRegion(e.Graphics); }
底下不错看下加第二段代码与不加的分辨
图片
图片
不错发现后果依然很显着的,终末咱们为了纯粹使用加入一个Type类型,来收场纯粹的换色后果
图片
按钮自界说控件已封装:
☛☛☛点击获得☚☚☚
图片
本站仅提供存储做事,通盘实质均由用户发布,如发现存害或侵权实质,请点击举报。- 上一篇:20余只低空经济主张股年内迎来翻倍行情
- 下一篇:没有了