/// <summary> /// 更新当前值 /// </summary> protected override void UpdateCurrentValue() { if (!updateCurrentValue) { return; } UICornerRadiusSides labelBorderSides = UICornerRadiusSides.None; if (allCheckBox.Checked) { currentValue = labelBorderSides | UICornerRadiusSides.All; allChecked = true; noneChecked = false; } else { if (noneCheckBox.Checked) { labelBorderSides |= UICornerRadiusSides.None; } if (leftTopCheckBox.Checked) { labelBorderSides |= UICornerRadiusSides.LeftTop; } if (rightTopCheckBox.Checked) { labelBorderSides |= UICornerRadiusSides.RightTop; } if (rightBottomCheckBox.Checked) { labelBorderSides |= UICornerRadiusSides.RightBottom; } if (leftBottomCheckBox.Checked) { labelBorderSides |= UICornerRadiusSides.LeftBottom; } if (labelBorderSides == UICornerRadiusSides.None) { allChecked = false; noneChecked = true; noneCheckBox.Checked = true; } if (labelBorderSides == UICornerRadiusSides.All) { allChecked = true; noneChecked = false; allCheckBox.Checked = true; } currentValue = labelBorderSides; } }
/// <summary> /// Ñùʽ»æÖÆÔ²½Ç /// </summary> /// <param name="control">¿Ø¼þ</param> /// <param name="bounds">·¶Î§</param> /// <param name="radius">Ô²½Ç´óС</param> /// <param name="roundStyle">Ô²½ÇÑùʽ</param> public static void CreateRegion( this Control control, Rectangle bounds, int radius, UICornerRadiusSides roundStyle) { using (GraphicsPath path = bounds.CreateRoundedRectanglePath(radius, roundStyle)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); control.Region = region; } }
/// <summary> /// 初始化数值 /// </summary> /// <param name="value">数值</param> protected override void InitValue(object value) { UICornerRadiusSides sides = (UICornerRadiusSides)value; ResetCheckBoxState(); if ((sides & UICornerRadiusSides.All) == UICornerRadiusSides.All) { allCheckBox.Checked = true; leftTopCheckBox.Checked = true; rightTopCheckBox.Checked = true; rightBottomCheckBox.Checked = true; leftBottomCheckBox.Checked = true; allCheckBox.Checked = true; } else { noneCheckBox.Checked = sides == UICornerRadiusSides.None; leftTopCheckBox.Checked = (sides & UICornerRadiusSides.LeftTop) == UICornerRadiusSides.LeftTop; rightTopCheckBox.Checked = (sides & UICornerRadiusSides.RightTop) == UICornerRadiusSides.RightTop; rightBottomCheckBox.Checked = (sides & UICornerRadiusSides.RightBottom) == UICornerRadiusSides.RightBottom; leftBottomCheckBox.Checked = (sides & UICornerRadiusSides.LeftBottom) == UICornerRadiusSides.LeftBottom; } }
/// <summary> /// 获取圆角是否设置 /// </summary> /// <param name="sides">所有圆角</param> /// <param name="side">当前圆角</param> /// <returns>是否有当前圆角</returns> public static bool GetValue(this UICornerRadiusSides sides, UICornerRadiusSides side) { return((sides & side) == side); }
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, UICornerRadiusSides radiusSides) { GraphicsPath path; if (radiusSides == UICornerRadiusSides.None || radius == 0) { Point[] points = new Point[] { new Point(0, 0), new Point(rect.Width, 0), new Point(rect.Width, rect.Height), new Point(0, rect.Height), new Point(0, 0), }; path = points.Path(); } else { //IsRadius为True时,显示左上圆角 bool RadiusLeftTop = radiusSides.GetValue(UICornerRadiusSides.LeftTop); //IsRadius为True时,显示左下圆角 bool RadiusLeftBottom = radiusSides.GetValue(UICornerRadiusSides.LeftBottom); //IsRadius为True时,显示右上圆角 bool RadiusRightTop = radiusSides.GetValue(UICornerRadiusSides.RightTop); //IsRadius为True时,显示右下圆角 bool RadiusRightBottom = radiusSides.GetValue(UICornerRadiusSides.RightBottom); path = rect.CreateRoundedRectanglePath(radius, RadiusLeftTop, RadiusRightTop, RadiusRightBottom, RadiusLeftBottom); } return(path); }
public static GraphicsPath CreateRoundedRectanglePath(this Graphics g, Rectangle rect, int radius, UICornerRadiusSides radiusSides) { return(rect.CreateRoundedRectanglePath(radius, radiusSides)); }
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, UICornerRadiusSides radiusSides, int lineSize = 1) { GraphicsPath path; if (radiusSides == UICornerRadiusSides.None || radius == 0) { path = rect.GraphicsPath(); } else { //IsRadius为True时,显示左上圆角 bool RadiusLeftTop = radiusSides.GetValue(UICornerRadiusSides.LeftTop); //IsRadius为True时,显示左下圆角 bool RadiusLeftBottom = radiusSides.GetValue(UICornerRadiusSides.LeftBottom); //IsRadius为True时,显示右上圆角 bool RadiusRightTop = radiusSides.GetValue(UICornerRadiusSides.RightTop); //IsRadius为True时,显示右下圆角 bool RadiusRightBottom = radiusSides.GetValue(UICornerRadiusSides.RightBottom); path = rect.CreateRoundedRectanglePath(radius, RadiusLeftTop, RadiusRightTop, RadiusRightBottom, RadiusLeftBottom, lineSize); } return(path); }