[Handler(Graphics.IHandler)] public class Graphics : Widget
Graphics context object for drawing operations
Remarks: This class allows you to draw on either a Bitmap or a Drawable control.

Constructors

Graphics

#
public Graphics(Bitmap image)
Initializes a new instance of the Generator class to draw on the given image
Remarks: To commit the changes to the Bitmap, the Graphics object must be disposed or used with a using block.
image (Bitmap)Image to draw on using this graphics context

Graphics

#
public Graphics(IHandler handler)
Initializes a new instance of the Graphics class with the specified platform handler

Properties

AntiAlias

#
public bool AntiAlias { get; set; }
Gets or sets a value indicating that drawing operations will use anti-aliasing

ClipBounds

#
public RectangleF ClipBounds { get; }
Gets the bounds of the clipping region
Remarks: This rectangle will encompass all parts of the clipping region, which may not be rectangular in shape
The clip bounds applied to drawing operations

ControlObject

public object ControlObject { get; }
Gets the instance of the platform-specific object
inherited fromWidget
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Widget.Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.

CurrentTransform

#
public IMatrix CurrentTransform { get; }
Gets a copy of the current transform.
Remarks: The current transform is initially an identity matrix. Any transform operations performed on this object will change this value.
The current transform matrix.

DPI

#
public float DPI { get; }
Gets the dots per inch of the current graphics context. Usually 96 for windows and 72 for other systems

Handler

public object Handler { get; }
Gets the platform-specific handler for this widget
inherited fromWidget

ImageInterpolation

#
public ImageInterpolation ImageInterpolation { get; set; }
Gets or sets the interpolation mode for drawing images

IsDisposed

public bool IsDisposed { get; }
Gets or sets a value indicating whether this Widget has been disposed.
inherited fromWidget
Remarks: When the widget is disposed, it can no longer be used.
true if this instance has been disposed; otherwise, false.

IsRetained

#
public bool IsRetained { get; }
Gets a value indicating the graphics sub-system is a retained system (e.g. WPF)
Remarks: Retained mode systems may have different behaviour characteristics, which may impact how often the screen is updated or other code.

NativeHandle

public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
inherited fromWidget

PixelOffsetMode

#
public PixelOffsetMode PixelOffsetMode { get; set; }
Gets or sets the pixel offset mode for draw operations

PixelsPerPoint

#
public float PixelsPerPoint { get; }
Gets the scale of points to pixels. Multiply by point value to get pixel size
Remarks: A value of 1.0 indicates that one pixel equals one point. Windows is usually 1 1/3 (96 dpi) while other systems are usually 1.0 (e.g. linux, os x)

Platform

public Platform Platform { get; }
Gets the platform that was used to create the Widget.Handler for this widget
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object

PointsPerPixel

#
public float PointsPerPixel { get; }
Gets the scale of points per pixel. Multiply by pixel size to get point value (e.g. to set font size in pixels).
Remarks: A value of 1.0 indicates that one point equals one pixel. Windows is usually 0.75 (96 dpi) while other systems are usually 1.0 (e.g. linux, os x)

Properties

public PropertyStore Properties { get; }
Gets the dictionary of properties for this widget
inherited fromWidget

Style

public string Style { get; set; }
Gets or sets the style of this widget
inherited fromWidget
Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
// in your UI
var control = new Button { Style = "mystyle" };

// in your platform assembly
using Eto.Mac.Forms.Controls;

Styles.AddHandler<ButtonHandler>("mystyle", handler => {
	// this is where you can use handler.Control to set properties, handle events, etc.
	handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});

Methods

Clear

#
public void Clear(Color color)
Resets all pixels in the ClipBounds region with the specified color

Clear

#
public void Clear(SolidBrush brush = null)
Resets all pixels in the ClipBounds region with the specified brush

Dispose

protected virtual void Dispose(bool disposing)
Handles the disposal of this widget
inherited fromWidget
disposing (bool)True if the caller called Widget.Dispose() manually, false if being called from a finalizer

DrawArc

#
public void DrawArc(Color color, float x, float y, float width, float height, float startAngle, float sweepAngle)
Draws a 1 pixel wide arc with the specified color
color (Color)Color of the arc
x (float)X co-ordinate of the upper left corner of the arc
y (float)Y co-ordinate of the upper left corner of the arc
width (float)Width of the arc
height (float)Height of the arc
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the arc

DrawArc

#
public void DrawArc(Color color, RectangleF rectangle, float startAngle, float sweepAngle)
Draws a 1 pixel wide arc with the specified color
color (Color)Color of the arc
rectangle (RectangleF)Location of the arc
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the arc

DrawArc

#
public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
Draws an arc with the specified pen
pen (Pen)Pen to draw the arc
x (float)X co-ordinate of the upper left corner of the arc
y (float)Y co-ordinate of the upper left corner of the arc
width (float)Width of the arc
height (float)Height of the arc
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the arc

DrawArc

#
public void DrawArc(Pen pen, RectangleF rectangle, float startAngle, float sweepAngle)
Draws an arc with the specified pen
pen (Pen)Pen to draw the arc
rectangle (RectangleF)Location of the arc
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the arc

DrawEllipse

#
public void DrawEllipse(Color color, float x, float y, float width, float height)
Draws a 1 pixel wide ellipse outline with the specified color
color (Color)Fill color
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the ellipse
height (float)Height of the ellipse

DrawEllipse

#
public void DrawEllipse(Color color, RectangleF rectangle)
Draws a 1 pixel wide ellipse outline with the specified color
color (Color)Color to outline the ellipse
rectangle (RectangleF)Location for the ellipse

DrawEllipse

#
public void DrawEllipse(Pen pen, float x, float y, float width, float height)
Draws an ellipse with the specified pen
pen (Pen)Pen to outline the ellipse
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the ellipse
height (float)Height of the ellipse

DrawEllipse

#
public void DrawEllipse(Pen pen, RectangleF rectangle)
Draws an ellipse outline with the specified pen

DrawImage

#
public void DrawImage(Image image, float x, float y, float width, float height)
Draws the specified image in a rectangle
Remarks: This will scale the image to the specified width and height using the ImageInterpolation mode
image (Image)Image to draw
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Destination width of the image to draw
height (float)Destination height of the image to draw

DrawImage

#
public void DrawImage(Image image, float x, float y)
Draws the specified image at a location with no scaling

DrawImage

#
public void DrawImage(Image image, PointF location)
Draws the specified image at a location with no scaling

DrawImage

#
public void DrawImage(Image image, RectangleF rectangle)
Draws the specified image in a rectangle
Remarks: This will scale the image to the specified width and height using the ImageInterpolation mode
image (Image)Image to draw
rectangle (RectangleF)Where to draw the image

DrawImage

#
public void DrawImage(Image image, RectangleF source, PointF destination)
Draws the source portion of an image, scaling to the specified destination
image (Image)Image to draw
source (RectangleF)Source rectangle of the image portion to draw
destination (PointF)Destination rectangle of where to draw the portion

DrawImage

#
public void DrawImage(Image image, RectangleF source, RectangleF destination)
Draws the source portion of an image, scaling to the specified destination
image (Image)Image to draw
source (RectangleF)Source rectangle of the image portion to draw
destination (RectangleF)Destination rectangle of where to draw the portion

DrawInsetRectangle

#
public void DrawInsetRectangle(Color topLeftColor, Color bottomRightColor, RectangleF rectangle, int width = 1)
Draws an rectangle with colors on the top/left and bottom/right with the given width
topLeftColor (Color)Color for top/left edges
bottomRightColor (Color)Color for bottom/right edges
rectangle (RectangleF)Outside of inset rectangle to draw
width (int = 1)Width of the rectangle, in pixels

DrawLine

#
public void DrawLine(Color color, float startx, float starty, float endx, float endy)
Draws a 1 pixel wide line with the specified color
color (Color)Color of the line
startx (float)X co-ordinate of the starting point
starty (float)Y co-ordinate of the starting point
endx (float)X co-ordinate of the ending point
endy (float)Y co-ordinate of the ending point

DrawLine

#
public void DrawLine(Color color, PointF start, PointF end)
Draws a 1 pixel wide line with the specified color
color (Color)Color of the line to draw
start (PointF)Starting location
end (PointF)Ending location

DrawLine

#
public void DrawLine(Pen pen, float startx, float starty, float endx, float endy)
Draws a line with the specified pen
pen (Pen)Pen to draw the line with
startx (float)X co-ordinate of the starting point
starty (float)Y co-ordinate of the starting point
endx (float)X co-ordinate of the ending point
endy (float)Y co-ordinate of the ending point

DrawLine

#
public void DrawLine(Pen pen, PointF start, PointF end)
Draws a line with the specified pen
pen (Pen)Pen to draw the line with
start (PointF)Starting location
end (PointF)Ending location

DrawLines

#
public void DrawLines(Color color, IEnumerable<PointF> points)
Draws a 1 pixel wide set of lines with the specified points

DrawLines

#
public void DrawLines(Color color, params PointF[] points)
Draws a 1 pixel wide set of lines with the specified points
color (Color)Color to draw the lines
points (params PointF[])Points for each of the lines

DrawLines

#
public void DrawLines(Pen pen, IEnumerable<PointF> points)
Draws a set of lines with the specified points

DrawLines

#
public void DrawLines(Pen pen, params PointF[] points)
Draws a set of lines with the specified points
pen (Pen)Pen to draw the lines with
points (params PointF[])Points for each of the lines

DrawPath

#
public void DrawPath(Color color, IGraphicsPath path)
Draws a 1 pixel outline of the specified path

DrawPath

#
public void DrawPath(Pen pen, IGraphicsPath path)
Draws the specified path

DrawPolygon

#
public void DrawPolygon(Color color, params PointF[] points)
Draws a 1 pixel wide outline of a polygon with the specified points
color (Color)Color to draw the polygon lines
points (params PointF[])Points of the polygon

DrawPolygon

#
public void DrawPolygon(Pen pen, params PointF[] points)
Draws an outline of a polygon with the specified points
pen (Pen)Pen to draw the polygon lines with
points (params PointF[])Points of the polygon

DrawRectangle

#
public void DrawRectangle(Color color, float x, float y, float width, float height)
Draws a 1 pixel wide outline of a rectangle with the specified color
color (Color)Color for the outline
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the rectangle
height (float)Height of the rectangle

DrawRectangle

#
public void DrawRectangle(Color color, RectangleF rectangle)
Draws a 1 pixel wide outline of a rectangle with the specified color

DrawRectangle

#
public void DrawRectangle(Pen pen, float x, float y, float width, float height)
Draws a rectangle
pen (Pen)Pen to outline the rectangle
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the rectangle
height (float)Height of the rectangle

DrawRectangle

#
public void DrawRectangle(Pen pen, RectangleF rectangle)
Draws a rectangle
pen (Pen)Pen to outline the rectangle
rectangle (RectangleF)Where to draw the rectangle

DrawText

#
public void DrawText(Font font, Brush brush, float x, float y, string text)
Draws text with the specified font, brush and location
font (Font)Font to draw the text with
brush (Brush)Brush to stroke the text
x (float)X co-ordinate of where to start drawing the text
y (float)Y co-ordinate of where to start drawing the text
text (string)Text string to draw

DrawText

#
public void DrawText(Font font, Brush brush, PointF location, string text)
Draws text with the specified font, brush and location
font (Font)Font to draw the text with
brush (Brush)Brush to stroke the text
location (PointF)Location of where to start drawing the text
text (string)Text string to draw

DrawText

#
public void DrawText(Font font, Brush brush, RectangleF frame, string text, FormattedTextWrapMode wrap = FormattedTextWrapMode.Word, FormattedTextAlignment alignment = FormattedTextAlignment.Left, FormattedTextTrimming trimming = FormattedTextTrimming.WordEllipsis)
Draws text in a rectangle with the specified formatted text trimming
font (Font)Font to draw the text with
brush (Brush)Brush to fill the text path
frame (RectangleF)Frame for the text to be drawn into
text (string)String to draw
wrap (FormattedTextWrapMode = FormattedTextWrapMode.Word)Wrap mode for the text
alignment (FormattedTextAlignment = FormattedTextAlignment.Left)Alignment of the text in the specified rectangle
trimming (FormattedTextTrimming = FormattedTextTrimming.WordEllipsis)Trimming to apply if the text does not fit in the supplied rectangle

DrawText

#
public void DrawText(Font font, Color color, float x, float y, string text)
Draws text with the specified font, color and location
font (Font)Font to draw the text with
color (Color)Color of the text
x (float)X co-ordinate of where to start drawing the text
y (float)Y co-ordinate of where to start drawing the text
text (string)Text string to draw

DrawText

#
public void DrawText(Font font, Color color, PointF location, string text)
Draws text with the specified font, color and location
font (Font)Font to draw the text with
color (Color)Color of the text
location (PointF)Location of where to start drawing the text
text (string)Text string to draw

DrawText

#
public void DrawText(Font font, SolidBrush brush, float x, float y, string text)
Draws text with the specified font, brush and location
font (Font)Font to draw the text with
brush (SolidBrush)Brush to stroke the text
x (float)X co-ordinate of where to start drawing the text
y (float)Y co-ordinate of where to start drawing the text
text (string)Text string to draw

DrawText

#
public void DrawText(Font font, SolidBrush brush, PointF location, string text)
Draws text with the specified font, brush and location
font (Font)Font to draw the text with
brush (SolidBrush)Brush to stroke the text
location (PointF)Location of where to start drawing the text
text (string)Text string to draw

DrawText

#
public void DrawText(FormattedText formattedText, PointF location)
Draws formatted text at the specified location
formattedText (FormattedText)Formatted text to draw
location (PointF)Location to draw the text

FillEllipse

#
public void FillEllipse(Brush brush, float x, float y, float width, float height)
Fills an ellipse with the specified brush
brush (Brush)Brush to fill the ellipse
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the ellipse
height (float)Height of the ellipse

FillEllipse

#
public void FillEllipse(Brush brush, RectangleF rectangle)
Fills an ellipse with the specified brush

FillEllipse

#
public void FillEllipse(Color color, float x, float y, float width, float height)
Fills an ellipse with the specified color
color (Color)Fill color
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the ellipse
height (float)Height of the ellipse

FillEllipse

#
public void FillEllipse(Color color, RectangleF rectangle)
Fills an ellipse with the specified color

FillPath

#
public void FillPath(Brush brush, IGraphicsPath path)
Fills the specified path

FillPath

#
public void FillPath(Color color, IGraphicsPath path)
Fills the specified path

FillPie

#
public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
Fills a pie with the specified brush
brush (Brush)Brush to fill the pie
x (float)X co-ordinate of the upper left corner of the pie
y (float)Y co-ordinate of the upper left corner of the pie
width (float)Width of the pie
height (float)Height of the pie
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the pie

FillPie

#
public void FillPie(Brush brush, RectangleF rectangle, float startAngle, float sweepAngle)
Fills a pie with the specified brush
brush (Brush)Brush to fill the pie
rectangle (RectangleF)Location of the pie
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the pie

FillPie

#
public void FillPie(Color color, float x, float y, float width, float height, float startAngle, float sweepAngle)
Fills a pie with the specified color
color (Color)Fill color
x (float)X co-ordinate of the upper left corner of the pie
y (float)Y co-ordinate of the upper left corner of the pie
width (float)Width of the pie
height (float)Height of the pie
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the pie

FillPie

#
public void FillPie(Color color, RectangleF rectangle, float startAngle, float sweepAngle)
Fills a pie with the specified color
color (Color)Fill color
rectangle (RectangleF)Location of the pie
startAngle (float)Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie
sweepAngle (float)Angle in degrees from the startAngle to the ending point of the pie

FillPolygon

#
public void FillPolygon(Brush brush, params PointF[] points)
Fills a polygon defined by points with the specified brush
brush (Brush)Brush to fill the polygon
points (params PointF[])Points of the polygon

FillPolygon

#
public void FillPolygon(Color color, params PointF[] points)
Fills a polygon defined by points with the specified color

FillRectangle

#
public void FillRectangle(Brush brush, float x, float y, float width, float height)
Fills a rectangle with the specified brush
brush (Brush)Brush to fill the rectangle
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the rectangle
height (float)Height of the rectangle

FillRectangle

#
public void FillRectangle(Brush brush, RectangleF rectangle)
Fills a rectangle with the specified brush
brush (Brush)Brush to fill the rectangle
rectangle (RectangleF)Location for the rectangle

FillRectangle

#
public void FillRectangle(Color color, float x, float y, float width, float height)
Fills a rectangle with the specified color
color (Color)Fill color
x (float)X co-ordinate
y (float)Y co-ordinate
width (float)Width of the rectangle
height (float)Height of the rectangle

FillRectangle

#
public void FillRectangle(Color color, RectangleF rectangle)
Fills a rectangle with the specified color

FillRectangles

#
public void FillRectangles(Brush brush, IEnumerable<RectangleF> rectangles)
Fills the specified rectangles
brush (Brush)Brush to fill the rectangles
rectangles (IEnumerable<RectangleF>)Enumeration of rectangles to fill

FillRectangles

#
public void FillRectangles(Color color, IEnumerable<RectangleF> rectangles)
Fills the specified rectangles
color (Color)Color to fill the rectangles
rectangles (IEnumerable<RectangleF>)Enumeration of rectangles to fill

Flush

#
public void Flush()
Flushes the drawing (for some platforms)
Remarks: Flushing the drawing will force any undrawn changes to be shown to the user. Typically when you are doing a lot of drawing, you may want to flush the changed periodically so that the user does not think the UI is unresponsive. Some platforms may not have the concept of flushing the graphics, so this would do nothing

GetCallback

protected virtual object GetCallback()
Gets an instance of an object used to perform callbacks to the widget from handler implementations
inherited fromWidget
Remarks: The callback should implement the parent class' Widget.ICallback interface so that there only needs to be a single callback for the entire hierarchy. This should return a static instance to avoid having overhead for each instance of your control.
The callback instance to use for this widget

Initialize

protected void Initialize()
Initializes the widget handler
inherited fromWidget
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.

IsVisible

#
public virtual bool IsVisible(RectangleF rectangle)
Returns true if the clip region intersects the specified rectangle.

MeasureString

#
public virtual SizeF MeasureString(Font font, string text)
Measures the string with the given font
font (Font)Font to measure with
text (string)Text string to measure
Size representing the dimensions of the entire text would take to draw given the specified font

MultiplyTransform

#
public void MultiplyTransform(IMatrix matrix)
Multiplies the co-ordinate system with the given matrix

OnStyleChanged

protected virtual void OnStyleChanged(EventArgs e)
Handles when the Widget.Style is changed.
inherited fromWidget

ResetClip

#
public void ResetClip()
Resets the clip bounds to encompass the entire drawing area

RestoreTransform

#
public void RestoreTransform()
Restores the transform state
Remarks: This restores the transform state from a previous SaveTransform() call. You must balance calls to SaveTransform() with calls to this method.

RotateTransform

#
public void RotateTransform(float angle)
Rotates the co-ordinate system by the given angle

SaveTransform

#
public void SaveTransform()
Saves the current transform state
Remarks: This saves the current transform state that can be changed by any of the transform calls, which can then be restored using RestoreTransform()

SaveTransformState

#
public IDisposable SaveTransformState()
Gets an object that will restore to the current transform state when disposed.
Remarks: This saves the current transform state that can be changed by any of the transform calls. This is useful when calling into untrusted code that can leave the transform unbalanced. It also ensures that RestoreTransform() requires a matching SaveTransform(), until the return value is disposed. Disposing the return value guarantees that the transform state is restored to when this method was called.
This example shows how you can reliably restore state in a code block:
using (graphics.SaveTransformState())
{
	// ...

	graphics.SaveTransform();
	graphics.MultiplyTransform(...);

	// ... other messy drawing code that doesn't call RestoreTransform()
}

ScaleTransform

#
public void ScaleTransform(float scale)
Scales the co-ordinate system by a factor
scale (float)Amount to scale in both the horizontal and vertical axis

ScaleTransform

#
public void ScaleTransform(float scaleX, float scaleY)
Scales the co-ordinate system by a factor
scaleX (float)Amount to scale the horizontal axis
scaleY (float)Amount to scale the vertical axis

ScaleTransform

#
public void ScaleTransform(SizeF scale)
Scales the co-ordinate system by a factor

SetClip

#
public void SetClip(IGraphicsPath path)
Sets the clip region to the specified path
Remarks: The previous clipping region will be cleared after this call The path specified is translated by the current transform, but is not affected by subsequent transform operations.
path (IGraphicsPath)Path to specify the clip region

SetClip

#
public void SetClip(RectangleF rectangle)
Sets the clip region to the specified rectangle
Remarks: The previous clipping region will be cleared after this call. The rectangle specified is translated by the current transform, but is not affected by subsequent transform operations.
rectangle (RectangleF)Rectangle for the clipping region

ToString

public override string ToString()
Gets a string that represents the current object with its ID if specified.
inherited fromWidget
A string value indicating the type and ID (if specified) of this widget.
Object.ToString

TranslateTransform

#
public void TranslateTransform(float offsetX, float offsetY)
Translates the origin of the co-ordinate system by the given offset
offsetX (float)Offset to translate the X co-ordinate
offsetY (float)Offset to translate the Y co-ordinate

TranslateTransform

#
public void TranslateTransform(PointF offset)
Translates the origin of the co-ordinate system by the given offset

Events