CPF/CPF/ThicknessField.cs
2023-11-21 23:05:03 +08:00

83 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace CPF
{
[Description("表示四周的厚度可以用百分比格式all或者left,top,right,bottom")]
public struct ThicknessField
{
/// <summary>
/// 表示四周的厚度 This constructur builds a Thickness with a specified value on every side.
/// </summary>
/// <param name="uniformLength">The specified uniform length.</param>
public ThicknessField(in FloatField uniformLength)
{
Left = Top = Right = Bottom = uniformLength;
}
/// <summary>
/// This constructor builds a Thickness with the specified number of pixels on each side.
/// 表示四周的厚度
/// </summary>
/// <param name="left">The thickness for the left side.</param>
/// <param name="top">The thickness for the top side.</param>
/// <param name="right">The thickness for the right side.</param>
/// <param name="bottom">The thickness for the bottom side.</param>
public ThicknessField(in FloatField left, in FloatField top, in FloatField right, in FloatField bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public FloatField Top { get; set; }
public FloatField Bottom { get; set; }
public FloatField Left { get; set; }
public FloatField Right { get; set; }
public static implicit operator ThicknessField(string n)
{
if (string.IsNullOrWhiteSpace(n))
{
throw new Exception("Thickness字符转换格式不对");
}
if (n.IndexOf(',') >= 0)
{
var temp = n.Split(',');
if (temp.Length < 4)
{
throw new Exception("Thickness字符转换格式不对");
}
try
{
return new ThicknessField(temp[0].Trim(), temp[1].Trim(), temp[2].Trim(), temp[3].Trim());
}
catch (Exception)
{
throw new Exception("Thickness字符转换格式不对");
}
}
else
{
try
{
return new ThicknessField(n);
}
catch (Exception)
{
throw new Exception("Thickness字符转换格式不对");
}
}
}
public override string ToString()
{
return $"{Left},{Top},{Right},{Bottom}";
}
}
}