/// <summary> /// Set the border of an <see cref="ExcelRange"/>. /// </summary> public static void SetBorder(this ExcelRange excelRange, BorderDirection borderDirection, BorderStyle borderStyle, Color borderColor) { _ = excelRange?.Style?.Border ?? throw new ArgumentException(ExceptionMessages.ExcelRangeNull); var mappedStyle = (OfficeOpenXml.Style.ExcelBorderStyle)borderStyle; switch (borderDirection) { case BorderDirection.Left: excelRange.Style.Border.Left.Style = mappedStyle; excelRange.Style.Border.Left.Color.SetColor(borderColor); break; case BorderDirection.Right: excelRange.Style.Border.Right.Style = mappedStyle; excelRange.Style.Border.Right.Color.SetColor(borderColor); break; case BorderDirection.Top: excelRange.Style.Border.Top.Style = mappedStyle; excelRange.Style.Border.Top.Color.SetColor(borderColor); break; case BorderDirection.Bottom: excelRange.Style.Border.Bottom.Style = mappedStyle; excelRange.Style.Border.Bottom.Color.SetColor(borderColor); break; case BorderDirection.Diagonal: excelRange.Style.Border.Diagonal.Style = mappedStyle; excelRange.Style.Border.Diagonal.Color.SetColor(borderColor); break; case BorderDirection.DiagonalUp: excelRange.Style.Border.Diagonal.Style = mappedStyle; excelRange.Style.Border.Diagonal.Color.SetColor(borderColor); excelRange.Style.Border.DiagonalUp = true; break; case BorderDirection.DiagonalDown: excelRange.Style.Border.Diagonal.Style = mappedStyle; excelRange.Style.Border.Diagonal.Color.SetColor(borderColor); excelRange.Style.Border.DiagonalDown = true; break; case BorderDirection.Around: excelRange.SetBorderAround(mappedStyle, borderColor); break; case BorderDirection.None: // No action. break; default: var exception = new InvalidOperationException(ExceptionMessages.UnknownBorderDirection); exception.Data.Add(nameof(borderDirection), borderDirection); throw exception; } }
/// <summary> /// Constructor /// </summary> /// <param name="textField">A UITextField</param> /// <param name="color">The desired border color</param> /// <param name="direction">The border directions to color</param> /// <param name="borderWidth">The desired border width</param> public BorderedTextField(UITextField textField, CGColor color, BorderDirection direction, nfloat borderWidth) { TextField = textField; BorderColor = color; BorderDirection = direction; BorderWidth = borderWidth; Color(); }
public BorderDirection GetDirection(float xPosition, float yPosition) { BorderDirection direction = BorderDirection.None; // check bottom left corner if (xPosition < borderInterface.TouchThickness && yPosition > WindowSize.Height + borderInterface.BorderHeight - borderInterface.TouchThickness) { direction = BorderDirection.BottomLeft; } // check bottom right corner else if (xPosition > WindowSize.Width + borderInterface.BorderLineThickness * 2 - borderInterface.TouchThickness && yPosition > WindowSize.Height + borderInterface.BorderHeight - borderInterface.TouchThickness) { direction = BorderDirection.BottomRight; } // check top left corner else if (xPosition < borderInterface.TouchThickness && yPosition < borderInterface.TouchThickness) { direction = BorderDirection.TopLeft; } // check top right corner else if (xPosition > WindowSize.Width + borderInterface.BorderLineThickness * 2 - borderInterface.TouchThickness && yPosition < borderInterface.TouchThickness) { direction = BorderDirection.TopRight; } // check left side else if (xPosition < borderInterface.TouchThickness) { direction = BorderDirection.Left; } // check right side else if (xPosition > WindowSize.Width + borderInterface.BorderLineThickness * 2 - borderInterface.TouchThickness) { direction = BorderDirection.Right; } // check bottom side else if (yPosition > WindowSize.Height + borderInterface.BorderHeight + borderInterface.BorderLineThickness - borderInterface.TouchThickness) { direction = BorderDirection.Bottom; } // check top side else if (yPosition < borderInterface.TouchThickness) { direction = BorderDirection.Top; } // check move else if (yPosition > WindowSize.Height) { direction = BorderDirection.Move; } return(direction); }
public void Resize(BorderDirection direction, int offset) { switch (direction) { case BorderDirection.Up: Start = new(Start.X, Start.Y + offset); return; case BorderDirection.Down: End = new(End.X, End.Y + offset); return; case BorderDirection.Right: End = new(End.X + offset, End.Y); return; case BorderDirection.Left: Start = new(Start.X + offset, Start.Y); return; } }
void ExpandBorderProperty(CssPropertyDeclaration decl, BorderDirection borderDirection, List<CssPropertyDeclaration> newProps) { int j = decl.ValueCount; for (int i = 0; i < j; ++i) { CssCodePrimitiveExpression cssCodePropertyValue = decl.GetPropertyValue(i) as CssCodePrimitiveExpression; if (cssCodePropertyValue == null) { continue; } //what value means ? //border width/ style / color if (cssCodePropertyValue.Hint == CssValueHint.Number || UserMapUtil.IsNamedBorderWidth(cssCodePropertyValue.Value)) { //border width switch (borderDirection) { default: case BorderDirection.All: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderLeftWidth, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderTopWidth, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderRightWidth, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderBottomWidth, cssCodePropertyValue)); } break; case BorderDirection.Left: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderLeftWidth, cssCodePropertyValue)); } break; case BorderDirection.Right: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderRightWidth, cssCodePropertyValue)); } break; case BorderDirection.Top: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderTopWidth, cssCodePropertyValue)); } break; case BorderDirection.Bottom: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderBottomWidth, cssCodePropertyValue)); } break; } continue; } //------ if (UserMapUtil.IsBorderStyle(cssCodePropertyValue.Value)) { //border style switch (borderDirection) { default: case BorderDirection.All: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderLeftStyle, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderRightStyle, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderTopStyle, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderBottomStyle, cssCodePropertyValue)); } break; case BorderDirection.Left: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderLeftStyle, cssCodePropertyValue)); } break; case BorderDirection.Right: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderRightStyle, cssCodePropertyValue)); } break; case BorderDirection.Top: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderTopStyle, cssCodePropertyValue)); } break; case BorderDirection.Bottom: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderBottomStyle, cssCodePropertyValue)); } break; } continue; } string value = cssCodePropertyValue.ToString(); if (value.StartsWith("#")) { //expand border color switch (borderDirection) { default: case BorderDirection.All: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderLeftColor, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderTopColor, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderRightColor, cssCodePropertyValue)); newProps.Add(CloneProp(WellknownCssPropertyName.BorderBottomColor, cssCodePropertyValue)); } break; case BorderDirection.Left: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderLeftColor, cssCodePropertyValue)); } break; case BorderDirection.Right: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderRightColor, cssCodePropertyValue)); } break; case BorderDirection.Top: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderTopColor, cssCodePropertyValue)); } break; case BorderDirection.Bottom: { newProps.Add(CloneProp(WellknownCssPropertyName.BorderBottomColor, cssCodePropertyValue)); } break; } continue; } } }
/// <summary> /// HTML 스타일의 BORDER-TOP을 그림. /// </summary> /// <param name="g"></param> /// <param name="c"></param> /// <param name="Width"></param> /// <param name="BorderWidth"></param> /// <param name="startX"> /// direct의 위치에 따라 다음과 같이 시작 위치가 정해짐.(시계 방향) /// Top: 왼쪽에서 시작, Right: 위쪽에서 시작, Bottom : 오른쪽에서 시작, Left: 아래쪽에서 시작 /// </param> /// <param name="startY"> /// direct의 위치에 따라 다음과 같이 시작 위치가 정해짐.(시계 방향) /// Top: 왼쪽에서 시작, Right: 위쪽에서 시작, Bottom : 오른쪽에서 시작, Left: 아래쪽에서 시작 /// </param> /// <param name="direct"></param> /// <example> /// private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) /// { /// Graphics g = e.Graphics; /// /// Color c = Color.Transparent; /// BorderDirection direct = BorderDirection.Top; /// int BorderWidth = 10; /// int Width = 100; /// float startX = 0, startY = 0; /// /// for (int i = 0; i < 4; i++) /// { /// switch (i) /// { /// case 0: /// c = Color.Red; /// startX = 0; startY = 0; /// direct = BorderDirection.Top; /// break; /// case 1: /// c = Color.Green; /// startX = 100; startY = 0; /// direct = BorderDirection.Right; /// break; /// case 2: /// c = Color.Blue; /// startX = 100; startY = 100; /// direct = BorderDirection.Bottom; /// break; /// case 3: /// c = Color.Black; /// startX = 0; startY = 100; /// direct = BorderDirection.Left; /// break; /// } /// /// DrawBorder(g, c, Width, BorderWidth, /// startX, startY, direct); /// } /// } /// </example> private void DrawBorder(Graphics g, Color c, float startX, float startY, int Width, int BorderWidth, BorderDirection direct, HtmlBorderStyle BStyle) { RectangleF RectF = new RectangleF(0f, 0f, 0f, 0f); switch (BStyle) { case HtmlBorderStyle.solid: switch (direct) { case BorderDirection.Top: RectF.X = startX; RectF.Y = startY; RectF.Width = Width; RectF.Height = BorderWidth; break; case BorderDirection.Right: RectF.X = startX - BorderWidth; RectF.Y = startY; RectF.Width = BorderWidth; RectF.Height = Width; break; case BorderDirection.Bottom: RectF.X = startX; RectF.Y = startY - BorderWidth; RectF.Width = Width; RectF.Height = BorderWidth; break; case BorderDirection.Left: RectF.X = startX; RectF.Y = startY; RectF.Width = BorderWidth; RectF.Height = Width; break; } g.FillRectangle(new SolidBrush(c), RectF); break; case HtmlBorderStyle.double_: RectangleF RectF2 = new RectangleF(0f, 0f, 0f, 0f); //두개의 채워진 도형과 하나의 빈 도형을 그림. //가장 많은 너비를 갖는 우선순위는 첫번째 채워진 도형, 두번째 채워진 도형, 빈 도형임. int b2 = (int)CMath.RoundDown(BorderWidth / 3M); int b3 = (int)CMath.RoundDown((BorderWidth - b2) / 2M); int b1 = BorderWidth - b3 - b2; switch (direct) { case BorderDirection.Top: RectF.X = startX; RectF.Y = startY; RectF.Width = Width; RectF.Height = b1; RectF2.X = startX; RectF2.Y = startY + b1 + b2; RectF2.Width = Width; RectF2.Height = b3; break; case BorderDirection.Right: RectF.X = startX - BorderWidth; RectF.Y = startY; RectF.Width = b1; RectF.Height = Width; RectF2.X = startX - b3; RectF2.Y = startY; RectF2.Width = b3; RectF2.Height = Width; break; case BorderDirection.Bottom: RectF.X = startX; RectF.Y = startY - BorderWidth; RectF.Width = Width; RectF.Height = b1; RectF2.X = startX; RectF2.Y = startY - b3; RectF2.Width = Width; RectF2.Height = b3; break; case BorderDirection.Left: RectF.X = startX; RectF.Y = startY; RectF.Width = BorderWidth; RectF.Height = Width; RectF2.X = startX + b1 + b2; RectF2.Y = startY; RectF2.Width = b3; RectF2.Height = Width; break; } g.FillRectangles(new SolidBrush(c), new RectangleF[2] { RectF, RectF2 }); break; } }
/// <summary> /// Extension method for coloring a UIView's borders /// </summary> /// <param name="view">The UIView being operated on</param> /// <param name="color">Border color</param> /// <param name="width">Border width</param> /// <param name="direction">Border directions to color</param> public static void ColorBorders(this UIView view, CGColor color, nfloat width, BorderDirection direction) { // Loop through the four possible borders foreach (var border in ALL_BORDERS) { // Checks that the current border should be colored if ((border & direction) == border) { // Sublayer name var name = $"{COLOR_BORDERS_EXT}.{border.ToString()}"; // Attempt to find sublayer by name var sublayer = view.Layer.Sublayers? .FirstOrDefault(layer => layer.Name != null && layer.Name.Equals(name)); // If a sublayer does not already exist, create and add it if (sublayer == null) { sublayer = new CALayer(); view.Layer.AddSublayer(sublayer); } sublayer.Frame = GetBorderFrame(border); // Border Frame sublayer.Name = name; // Name the sublayer sublayer.BorderWidth = width; // Set the border width sublayer.BorderColor = color; // Set the border color } } // Gets the border frame based on the direction provided CGRect GetBorderFrame(BorderDirection border) { switch (border) { case BorderDirection.Top: return(new CGRect(0, 0, view.Frame.Width, width)); case BorderDirection.Bottom: return(new CGRect(0, view.Frame.Size.Height - width, view.Frame.Width, width)); case BorderDirection.Left: return(new CGRect(0, 0, width, view.Frame.Height)); case BorderDirection.Right: return(new CGRect(view.Frame.Width - width, 0, width, view.Frame.Height)); default: throw new NotSupportedException("That border direction is not supported"); } } }