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

    <P>Hello,</P>
    <P> </P>
    <P>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.</P>
    <P> </P><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
    <P>Dim</FONT></FONT><FONT size=2> ptsRect() </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> Point = { _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(1, 1), _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(1, 16), _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(16, 16), _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(16, 1) _</P>
    <P>}</P><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
    <P>Dim</FONT></FONT><FONT size=2> myColor </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> Color = Color.FromArgb(iAlpha, iRed, iGreen, iBlue)</P>
    <P></FONT><FONT size=2><FONT color=#008000>DIM </FONT>myBrush as HatchBrush = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> HatchBrush(HatchStyle.Trellis, Color.White, myColor)</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
    <P>Dim</FONT></FONT><FONT size=2> gpath </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Drawing.Drawing2D.GraphicsPath = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> System.Drawing.Drawing2D.GraphicsPath<BR>gpath.AddPolygon(ptsRect)<BR></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2> <BR></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> pso </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.DrawingSpace.CustomShape<BR></FONT><FONT size=2>pso.Shape = gpath</P></FONT>
    <P><FONT color=#008000 size=2><FONT color=#008000 size=2></P></FONT></FONT><FONT size=2></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> sProps </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.DrawingSpace.ShapeProps<BR>sProps.CreateGraphics.FillPath(myBrush, gpath) </FONT>
    <P><FONT color=#008000 size=2><FONT color=#008000 size=2></P>
    <P></FONT></FONT><FONT size=2>FpSpread1.ActiveSheet.AddShape(pso, 0, 0)</FONT></P>
    <P> </P>
    <P>Thanks,</P>
    <P>Scott</P>
  • Replied 8 September 2017, 1:32 pm EST

    <P>Scott,</P>
    <P>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.</P><FONT size=2>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> Button1_Click(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Object</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> Button1.Click</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> ptsRect() </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> Point = { _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(1, 1), _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(1, 160), _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(160, 160), _</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> Point(160, 1) _</P>
    <P>}</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> gpath </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Drawing.Drawing2D.GraphicsPath = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> System.Drawing.Drawing2D.GraphicsPath</P>
    <P>gpath.AddPolygon(ptsRect)</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> pso </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> myShape</P>
    <P>pso.Shape = gpath</P>
    <P>FpSpread1.ActiveSheet.AddShape(pso, 0, 0)</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</P>
    <P>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Class</P>
    <P>Public</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Class</FONT></FONT><FONT size=2> myShape</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Inherits</FONT></FONT><FONT size=2> FarPoint.Win.Spread.DrawingSpace.CustomShape</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Public</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Overrides</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> OnPaintBackground(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> g </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Drawing.Graphics, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> rectInput </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Drawing.Rectangle)</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> myColor </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> Color = Color.FromArgb(128, 120, 20, 100)</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> myBrush </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Drawing.Drawing2D.HatchBrush = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Trellis, Color.White, myColor)</P>
    <P>g.FillPath(myBrush, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>CType</FONT></FONT><FONT size=2>(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.Shape, System.Drawing.Drawing2D.GraphicsPath))</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</P>
    <P>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Class</P></FONT></FONT>
Need extra support?

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

Learn More

Forum Channels