Текстурная кисть с разделителем - PullRequest
1 голос
/ 05 сентября 2011

нужен метод для возврата переменной Texturebrush. Метод должен быть перегружен:

Size AreaSize,
int HorizontalSeperatorCount,
int VerticalSeperatorCount,
int SeperatorWidth,
Brush Seperatorbackground,
Brush Rectanglebackground,

Размер прямоугольника будет рассчитан автоматически


TextturebrushExample1

Эти примеры имеют следующие значения

Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 1,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red

TextturebrushExample2

Второй пример имеет другой VerticalSeperatorCount

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 будет использоваться для заполнения окна

TextturebrushExample3

Я не лучший в рисовании. Я был бы очень доволен решением.

1 Ответ

0 голосов
/ 06 сентября 2011
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;
}

Создайте проблему с большим количеством разделителей из-за округления. Это нормально для меня.

...