new Size(_roundRadius
序论:不知谈从什么工夫运行,寰宇心爱上了这种平滑式的缠绵,对于正本简通俗单、方合法正的缠绵运行置之不睬了(我到当今还独爱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类型,来终了通俗的换色效劳
图片
中国汽车工业进出口总公司按钮自界说控件已封装:
☛☛☛点击获得☚☚☚
图片
本站仅提供存储功绩,通盘履行均由用户发布,如发现存害或侵权履行,请点击举报。上一篇:没有了
下一篇:其后由斯纳克玛M88发动机取代