Northwoods.GoWeb Assembly > Northwoods.GoWeb Namespace : GoDrawing Class |
'Declaration <SerializableAttribute()> Public Class GoDrawing Inherits GoShape
[SerializableAttribute()] public class GoDrawing : GoShape
This shape class, the most capable of the GoShapes, is a generalization of the GoPolygon and GoStroke classes. You can also rotate or flip a drawing, extract figures as drawings, or insert other shapes as figures. The GoFigure enumeration specifies a number of predefined drawings.
The term "figure" is used in two different but related ways here. Inside a GoDrawing there can be more than one figure, where each figure is a closed or open series of straight or curved segments. Although most GoFigure enumerations specify GoDrawings consisting of a single figure, some of the more complicated GoFigures specify GoDrawings that contain multiple figures.
The most common usage is to just use the GoDrawing Constructor(GoFigure) constructor, followed by setting the GoShape.BrushColor, GoShape.PenColor, or other GoShape properties. Remember that an instance of a GoDrawing is a single GoShape, with a single GoShape.Brush and a single GoShape.Pen covering the whole shape.
You can define your own drawings by specifying the points and the nature of each segment, along with whether each figure is open or closed. In a manner similar to drawing with a pencil, for each figure you want to create, call the StartAt
method, call LineTo
and/or CurveTo
as many times as you need, followed by a call to CloseFigure
if you want that figure to be a closed path and potentially filled by the GoShape.Brush. For example, this produces an open shape consisting of two curves:
GoDrawing s = new GoDrawing(); s.StartAt(50, 50); s.CurveTo(75, 75, 100, 100, 50, 150); s.CurveTo(100, 150, 150, 100, 200, 200);This produces a square with two curved lines connecting the top-left corner with the bottom-right corner:
GoDrawing s = new GoDrawing(); s.StartAt(50, 50); s.LineTo(150, 50); s.LineTo(150, 150); s.LineTo(50, 150); s.LineTo(50, 50); s.CurveTo(125, 75, 125, 75, 150, 150); s.CurveTo(75, 125, 75, 125, 50, 50); s.CloseFigure(); s.BrushColor = Color.Green;The above drawing is completely filled by the green color. If you had not called CloseFigure, no brush would be painted in that figure. Users could only pick this drawing by clicking along the lines.
If you call CloseFigure and also set FillMode to FillMode.Alternate
, the inner area between the two curves will be open. No brush will be painted there, and ContainsPoint at any point in there will return false, although ContainsPoint will return true where the brush is painted.
Here's an example of creating a drawing with three figures: two squares connected by a line.
GoDrawing s = new GoDrawing(); s.StartAt(50, 50); s.LineTo(100, 50); s.LineTo(100, 100); s.LineTo(50, 100); s.CloseFigure(); s.StartAt(150, 50); s.LineTo(200, 50); s.LineTo(200, 100); s.LineTo(150, 100); s.CloseFigure(); s.StartAt(100, 75); s.LineTo(150, 75); s.FillSimpleGradient(Color.Green, GoObject.MiddleLeft);Note that the gradient extends all the way from the left side to the right side. The left square is relatively light colored; the right square is relatively dark.
You can rotate a drawing by setting the Angle property. Or you can rotate about any point by calling Rotate, which will also set the Angle. Please note that changing the angle may very well change the GoObject.Bounds, including the GoObject.Position. You can get the bounds of this drawing as if the angle were zero by using the UnrotatedBounds property. Just setting the Angle property will rotate the drawing about the UnrotatedCenter -- the center of the UnrotatedBounds.
You can also flip a drawing about either a horizontal axis or a vertical one.
When a drawing is GoObject.Resizable and GoObject.Reshapable, and when ReshapablePoints is true, the user will be able to drag any of the points of the drawing.
For figures that are have their first point and their last point at the same PointF
location, moving either shape might produce undesirable results unless the other point is moved too. Set the SameEndPoints property to true to have DoResizePointHandles (called by DoResize) keep both end points of figures together.
Adjacent curved segments may meet at an angle. Sometimes you would like to make sure that curves remain smooth between two curved segments, even when the user reshapes the points. You can set SmoothCurves, or call MakeSmoothCurves. But note that curved segments will still form angles with an adjacent straight line segments.
There are also methods for modifying individual points, for inserting segments into an existing figure, for opening or closing existing figures, for inserting whole shapes as figures into a drawing, and for extracting figures from a drawing into a new GoDrawing.
The basic points and segment style and figure information is stored in a GoDrawingData, accessible via the Data property. This information is used to construct a GraphicsPath
in the MakePath method.
The PointsCount property returns the number of points in the whole drawing. The FiguresCount property returns the number of figures in the whole drawing.
Since it is hard for a user to pick a figure when they have to precisely target pixels where the line is drawn, the ContainsPoint predicate allows for a certain amount of leeway. This is governed by the PickMargin property.
System.Object
Northwoods.GoWeb.GoObject
Northwoods.GoWeb.GoShape
Northwoods.GoWeb.GoDrawing
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2