C# 带分隔符图案的Texturebrush
需要返回变量Texturebrush的方法。该方法需要重载为:C# 带分隔符图案的Texturebrush,c#,gdi+,C#,Gdi+,需要返回变量Texturebrush的方法。该方法需要重载为: Size AreaSize, int HorizontalSeperatorCount, int VerticalSeperatorCount, int SeperatorWidth, Brush Seperatorbackground, Brush Rectanglebackground, 矩形的大小将自动计算 这些示例具有以下值 Size AreaSize = new Size(100, 100), int Horizon
Size AreaSize,
int HorizontalSeperatorCount,
int VerticalSeperatorCount,
int SeperatorWidth,
Brush Seperatorbackground,
Brush Rectanglebackground,
矩形的大小将自动计算
这些示例具有以下值
Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 1,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red
第二个示例具有不同的垂直分隔计数
Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 3,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red
方法的签名
public static TextureBrush GetTextureBrush(Size areaSize, int horizontalSeperator, int verticalSeperatorCount, int seperatorWidth, Brush seperatorBackground, Brush rectangleBackground)
Texturebrush将用于填充窗口 我不擅长绘画。 我会很高兴找到解决办法
public static TextureBrush GetSeperatorBrush(Size areaSize,
int horizontalSeperatorCount,
int verticalSeperatorCount,
int seperatorWidth,
Brush rectangleBackground)
{
var horizontalRectangleCount = horizontalSeperatorCount + 1.0f;
var verticalRectangleCount = verticalSeperatorCount + 1.0f;
var horizontalSeperatorBreadths = (horizontalSeperatorCount + 2.0f) * seperatorWidth;
var verticalSeperatorBreadths = (verticalSeperatorCount + 2.0f) * seperatorWidth;
var rectangleWidth = (areaSize.Width - verticalSeperatorBreadths) / verticalRectangleCount;
var rectangleHeight = (areaSize.Height - horizontalSeperatorBreadths) / horizontalRectangleCount;
var bitmap = new Bitmap((int)Math.Ceiling(rectangleWidth + seperatorWidth), (int)Math.Ceiling(rectangleHeight + seperatorWidth));
var graphics = Graphics.FromImage(bitmap);
var rectanglePoints = new[] { new PointF(seperatorWidth, seperatorWidth),
new PointF(seperatorWidth + rectangleWidth, seperatorWidth),
new PointF(seperatorWidth + rectangleWidth, seperatorWidth + rectangleHeight),
new PointF(seperatorWidth, seperatorWidth + rectangleHeight),
new PointF(seperatorWidth, seperatorWidth)};
graphics.FillPolygon(rectangleBackground, rectanglePoints);
graphics.Dispose();
var textureBrush = new TextureBrush(bitmap, System.Drawing.Drawing2D.WrapMode.Tile);
return textureBrush;
}
由于四舍五入,给许多分隔符制造了一些麻烦。对我来说没关系