Applying brush styles to custom shapes

Posted by: spfeiffer13 on 8 September 2017, 1:32 pm EST

  • Posted 8 September 2017, 1:32 pm EST

    Hello,


     


    I am trying to apply a hatchbrush style to fill a custom shape that is created and put in a cell.  I am able to create and color the shape but I can not find how to apply a brush style to fill the shape.


     


    Dim ptsRect() As Point = { _


    New Point(1, 1), _


    New Point(1, 16), _


    New Point(16, 16), _


    New Point(16, 1) _


    }


    Dim myColor As Color = Color.FromArgb(iAlpha, iRed, iGreen, iBlue)


    DIM myBrush as HatchBrush = New HatchBrush(HatchStyle.Trellis, Color.White, myColor)


    Dim gpath As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath
    gpath.AddPolygon(ptsRect)
     
    Dim pso As New FarPoint.Win.Spread.DrawingSpace.CustomShape
    pso.Shape = gpath


    Dim sProps As New FarPoint.Win.Spread.DrawingSpace.ShapeProps
    sProps.CreateGraphics.FillPath(myBrush, gpath)


    FpSpread1.ActiveSheet.AddShape(pso, 0, 0)


     


    Thanks,


    Scott

  • Replied 8 September 2017, 1:32 pm EST

    Scott,


    The way to do this is to inherit from the CustomShape object and override the OnPaintBackGround method to paint the shape with your hatch brush.


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


    Dim ptsRect() As Point = { _


    New Point(1, 1), _


    New Point(1, 160), _


    New Point(160, 160), _


    New Point(160, 1) _


    }


    Dim gpath As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath


    gpath.AddPolygon(ptsRect)


    Dim pso As New myShape


    pso.Shape = gpath


    FpSpread1.ActiveSheet.AddShape(pso, 0, 0)


    End Sub


    End Class


    Public Class myShape


    Inherits FarPoint.Win.Spread.DrawingSpace.CustomShape


    Public Overrides Sub OnPaintBackground(ByVal g As System.Drawing.Graphics, ByVal rectInput As System.Drawing.Rectangle)


    Dim myColor As Color = Color.FromArgb(128, 120, 20, 100)


    Dim myBrush As System.Drawing.Drawing2D.HatchBrush = New System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Trellis, Color.White, myColor)


    g.FillPath(myBrush, CType(Me.Shape, System.Drawing.Drawing2D.GraphicsPath))


    End Sub


    End Class

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels