Click or drag to resize

Brush Class

Represents a type which describes how the area is painted or filled.
Inheritance Hierarchy

Namespace:  SautinSoft.Document.Drawing
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.28 (3.8.6.28)
Syntax
public class Brush

The Brush type exposes the following members.

Properties
  NameDescription
Public propertyIsEmpty
Gets a value indicating whether the parent shape is filled.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleSetEmpty
Sets an empty fill on the parent shape (shape won't be filled).
Public methodCode exampleSetPicture(String)
Sets a picture fill on the parent shape.
Public methodCode exampleSetPicture(Stream, PictureFormat)
Sets a picture fill on the parent shape.
Public methodCode exampleSetSolid
Sets a solid color fill on the parent shape.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
Creates a new document with shape containing a text and picture using C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            PictureAndShape();
        }
        /// <summary>
        /// Creates a new document with shape containing a text and picture.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/pictures-and-shapes.php
        /// </remarks>
        static void PictureAndShape()
        {
            string filePath = @"Shape.docx";
            string imagePath = @"..\..\image.jpg";

            DocumentCore dc = new DocumentCore();                        

            // 1. Shape with text.
            Shape shapeWithText = new Shape(dc, Layout.Floating(new HorizontalPosition(1, LengthUnit.Inch, HorizontalPositionAnchor.Page), 
                new VerticalPosition(2, LengthUnit.Inch, VerticalPositionAnchor.Page),
                new Size(LengthUnitConverter.Convert(6, LengthUnit.Inch, LengthUnit.Point), LengthUnitConverter.Convert(1.5d, LengthUnit.Centimeter, LengthUnit.Point))));
            (shapeWithText.Layout as FloatingLayout).WrappingStyle = WrappingStyle.InFrontOfText;
            shapeWithText.Text.Blocks.Add(new Paragraph(dc, new Run(dc, "This is the text in shape.", new CharacterFormat() { Size  = 30})));
            shapeWithText.Outline.Fill.SetEmpty();
            shapeWithText.Fill.SetSolid(Color.Orange);
            dc.Content.End.Insert(shapeWithText.Content);            

            // 2. Picture with FloatingLayout:
            // Floating layout means that the Picture (or Shape) is positioned by coordinates.
            Picture pic = new Picture(dc, imagePath);
            pic.Layout = FloatingLayout.Floating(
                new HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page),
                new VerticalPosition(20, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point),
                         LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point))
                         );

            // Set the wrapping style.
            (pic.Layout as FloatingLayout).WrappingStyle = WrappingStyle.BehindText;

            // Add our picture into the section.
            dc.Content.End.Insert(pic.Content);

            dc.Save(filePath);

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
Creates a new document with shape containing a text and picture using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing

Module Sample
    Sub Main()
        PictureAndShape()
    End Sub

    ''' <summary>
    ''' Creates a new document with shape containing a text and picture.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/pictures-and-shapes.php
    ''' </remarks>
    Sub PictureAndShape()
        Dim filePath As String = "Shape.docx"
        Dim imagePath As String = "..\image.jpg"

        Dim dc As New DocumentCore()

        ' 1. Shape with text.
        Dim shapeWithText As New Shape(dc, Layout.Floating(New HorizontalPosition(1, LengthUnit.Inch, HorizontalPositionAnchor.Page), New VerticalPosition(2, LengthUnit.Inch, VerticalPositionAnchor.Page), New Size(LengthUnitConverter.Convert(6, LengthUnit.Inch, LengthUnit.Point), LengthUnitConverter.Convert(1.5R, LengthUnit.Centimeter, LengthUnit.Point))))
        TryCast(shapeWithText.Layout, FloatingLayout).WrappingStyle = WrappingStyle.InFrontOfText
        shapeWithText.Text.Blocks.Add(New Paragraph(dc, New Run(dc, "This is the text in shape.", New CharacterFormat() With {.Size = 30})))
        shapeWithText.Outline.Fill.SetEmpty()
        shapeWithText.Fill.SetSolid(Color.Orange)
        dc.Content.End.Insert(shapeWithText.Content)

        ' 2. Picture with FloatingLayout:
        ' Floating layout means that the Picture (or Shape) is positioned by coordinates.
        Dim pic As New Picture(dc, imagePath)
        pic.Layout = FloatingLayout.Floating(New HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page), New VerticalPosition(20, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), New Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point), LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point)))

        ' Set the wrapping style.
        TryCast(pic.Layout, FloatingLayout).WrappingStyle = WrappingStyle.BehindText

        ' Add our picture into the section.
        dc.Content.End.Insert(pic.Content)

        dc.Save(filePath)

        ' Show the result.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub
End Module
See Also