MonoTouch.CoreGraphics.CGContext Class
Graphics context and primitives to draw in them.

See Also: CGContext Members

Syntax

public class CGContext : MonoTouch.ObjCRuntime.INativeObject, IDisposable

Remarks

A MonoTouch.CoreGraphics.CGContext is a Quartz 2D destination for drawing. It holds parameters and their states (set with functions such as CGContext.SetFillColor) and device information (for instance, CGContext.ConvertSizeToDeviceSpace). MonoTouch.CoreGraphics.CGContexts may represent a screen area, a bitmap, a PDF document, or a printer.

There are a limited number of MonoTouch.CoreGraphics.CGContexts available and application developer's should be conscientious about disposing of them after use. Generally, that means putting the drawing code in using blocks, as shown in the following example:

C# Example

public override void Draw (RectangleF rect)
{
    base.Draw (rect);
    using (var context = UIGraphics.GetCurrentContext ())
    {
        // draw a rectangle using a path
	var myRectangleButtonPath = new CGPath ();
	myRectangleButtonPath.AddRect (new RectangleF (new PointF (100, 10), new SizeF (200, 400)));
	context.AddPath (myRectangleButtonPath);
	context.DrawPath (CGPathDrawingMode.Stroke);
    }
}          
          

The example additionally shows the very common pattern of an overridden MonoTouch.UIKit.UIView.Draw method in a custom MonoTouch.UIKit.UIView and the use of MonoTouch.UIKit.UIGraphics.GetCurrentContext to retrieve the current MonoTouch.CoreGraphics.CGContext on which to draw.

Related content

Requirements

Namespace: MonoTouch.CoreGraphics
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0