CanvasControl Class
Represents a control that supports custom rendering of content.
public class CanvasControl : UIElement, IInputElement, IUIElement, ILogicalTreeNode, IDisposable, ICanvas
- Inheritance:
- Object MarshalByRefObject DisposableObject LogicalTreeNodeBase UIElement Object
- Implements:
- IInputElement IUIElement ILogicalTreeNode IDisposable ICanvas
Constructors
CanvasControl()
Initializes an instance of the CanvasControl
class.
public CanvasControl()
CanvasControl(Boolean)
Initializes an instance of the CanvasControl
class.
public CanvasControl(bool isForPrinter)
Parameter | Type | Description |
---|---|---|
isForPrinter | Boolean | Whether this canvas is created for a printer. |
Properties
IsForPrinter
Gets whether this canvas is created for a printer.
protected bool IsForPrinter { get; }
Property Value
- Boolean:
true
if this canvas is created for a printer; otherwise,false
.
Methods
CreateDrawContext(ICanvas, Graphics, Rectangle)
Creates a CanvasDrawContext for the Draw event.
protected virtual CanvasDrawContext CreateDrawContext(ICanvas canvas, Graphics platformRenderer, Rectangle bounds)
Parameter | Type | Description |
---|---|---|
canvas | ICanvas | The ICanvas being drawn. |
platformRenderer | Graphics | The native object used for drawing. |
bounds | Rectangle | The bounds in which to draw. |
Returns
- CanvasDrawContext:
The CanvasDrawContext that was created.
CreateTextBatch()
Creates an IDisposable object that contains a reference to a text renderer, which can be passed to the RunTextFormatter(IDisposable) to more efficiently process multiple similar text layouts in a batch.
public IDisposable CreateTextBatch()
Returns
- IDisposable:
An IDisposable object. Once disposed, the batch is ended.
CreateTextLayout(ITextProvider, Single, String, Single, Color, FontWeights, FontStyles, IEnumerable<ITextSpacer>)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(ITextProvider textProvider, float maxWidth, string fontFamilyName, float fontSize, Color foreground, FontWeights fontWeight, FontStyles fontStyle, IEnumerable<ITextSpacer> spacers)
Parameter | Type | Description |
---|---|---|
textProvider | ITextProvider | An ITextProvider that provides access to the text string. |
maxWidth | Single | The maximum width of the layout, which is used if word wrap is enabled. |
fontFamilyName | String | The default font family name. |
fontSize | Single | The default font size. |
foreground | Color | The default foreground. |
fontWeight | FontWeights | The default font weight. |
fontStyle | FontStyles | The default font style. |
spacers | IEnumerable<ITextSpacer> | The optional intra-text spacers. |
Returns
- ITextLayout:
The ITextLayout that was created.
CreateTextLayout(ITextProvider, Single, String, Single, Color, IEnumerable<ITextSpacer>)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(ITextProvider textProvider, float maxWidth, string fontFamilyName, float fontSize, Color foreground, IEnumerable<ITextSpacer> spacers)
Parameter | Type | Description |
---|---|---|
textProvider | ITextProvider | An ITextProvider that provides access to the text string. |
maxWidth | Single | The maximum width of the layout, which is used if word wrap is enabled. |
fontFamilyName | String | The default font family name. |
fontSize | Single | The default font size. |
foreground | Color | The default foreground. |
spacers | IEnumerable<ITextSpacer> | The optional intra-text spacers. |
Returns
- ITextLayout:
The ITextLayout that was created.
CreateTextLayout(String, Single, String, Single, Color)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(string text, float maxWidth, string fontFamilyName, float fontSize, Color foreground)
Parameter | Type | Description |
---|---|---|
text | String | The text string. |
maxWidth | Single | The maximum width of the layout, which is used if word wrap is enabled. |
fontFamilyName | String | The default font family name. |
fontSize | Single | The default font size. |
foreground | Color | The default foreground. |
Returns
- ITextLayout:
The ITextLayout that was created.
CreateTextSpacer(Int32, Object, Size, Single)
Creates an ITextSpacer that can create intra-text space within an ITextLayout.
public ITextSpacer CreateTextSpacer(int characterIndex, object key, Size size, float baseline)
Parameter | Type | Description |
---|---|---|
characterIndex | Int32 | The character index at which the spacer should be inserted. |
key | Object | An optional object that uniquely identifies the spacer. |
size | Size | The size of the spacer. |
baseline | Single | The baseline of the spacer. |
Returns
- ITextSpacer:
The ITextSpacer that was created.
Dispose(Boolean)
Releases the unmanaged resources used by the object and optionally releases the managed resources.
protected override void Dispose(bool disposing)
Parameter | Type | Description |
---|---|---|
disposing | Boolean |
|
Remarks
This method is called by the public Dispose
method and the Finalize
method.
Dispose
invokes this method with the disposing
parameter set to true
.
Finalize
invokes this method with disposing
set to false
.
ExecuteFunc<T>(Func<T>)
Safely executes an Func<TResult> that deals with canvas resource creation and occurs outside of the Draw event handler.
public T ExecuteFunc<T>(Func<T> func)
- Type Parameters:
-
T
-
Parameter | Type | Description |
---|---|---|
func | Func<T> | The Func<TResult> to execute. |
Returns
- T:
true
if the canvas was ready and executed the function; otherwise,false
.
GetSolidColorBrush(Color)
Returns a solid color brush for the specified Color.
public SolidBrush GetSolidColorBrush(Color color)
Parameter | Type | Description |
---|---|---|
color | Color | The brush color. |
Returns
- SolidBrush:
A solid color brush for the specified Color.
GetSquiggleLinePen(Color)
Returns a squiggle line pen for the specified Color.
public Pen GetSquiggleLinePen(Color color)
Parameter | Type | Description |
---|---|---|
color | Color | The pen color. |
Returns
GetSquiggleLinePen(Color, Single)
Returns a squiggle line pen for the specified Color.
public Pen GetSquiggleLinePen(Color color, float thickness)
Parameter | Type | Description |
---|---|---|
color | Color | The pen color. |
thickness | Single | The pen thickness. |
Returns
InvalidateRender()
Invalidates and repaints the control.
public void InvalidateRender()
OnRender(PaintEventArgs)
Occurs when rendering the control.
protected override void OnRender(PaintEventArgs e)
Parameter | Type | Description |
---|---|---|
e | PaintEventArgs | The |
RenderToPrinter(Graphics, Rectangle)
Renders to an offscreen printer Graphics.
protected void RenderToPrinter(Graphics platformRenderer, Rectangle bounds)
Parameter | Type | Description |
---|---|---|
platformRenderer | Graphics | The Graphics to use. |
bounds | Rectangle | The bounds in which to render. |
Events
Draw
Occurs when the canvas should be rendered.
Inherited Members
- UIElement.IInputElement.RaiseClickEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseDoubleClickEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseDownEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseEnterEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseHoverEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseLeaveEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseMoveEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseUpEvent(MouseEventArgs)
- UIElement.IInputElement.RaiseMouseWheelEvent(MouseEventArgs)
- UIElement.IUIElement.GetDrawState()
- UIElement.IUIElement.HitTest(PointHitTestParameters)
- UIElement.IUIElement.HitTest(PointHitTestParameters, Func<IUIElement, PointHitTestParameters, Boolean>)
- UIElement.IUIElement.HitTestRecursive(PointHitTestParameters)
- UIElement.IUIElement.HitTestRecursive(PointHitTestParameters, Func<IUIElement, PointHitTestParameters, Boolean>)
- UIElement.IUIElement.NotifyChildDesiredSizeChanged()
- UIElement.IUIElement.NotifyMouseLeaveEvent()
- UIElement.AddPendingGraphicsInversion(Rectangle)
- UIElement.AddPendingScrollOperation(Rectangle, Orientation, Int32)
- UIElement.AddPendingScrollOperation(Rectangle, Int32, Int32)
- UIElement.Arrange(Rectangle)
- UIElement.ArrangeOverride(Size)
- UIElement.CaptureMouse()
- UIElement.ContainsLocation(Point)
- UIElement.CreateGraphics()
- UIElement.GetCursor(Point)
- UIElement.Invalidate()
- UIElement.Invalidate(Rectangle)
- UIElement.Invalidate(InvalidationLevels, InvalidationTypes)
- UIElement.InvalidateArrange()
- UIElement.InvalidateMeasure()
- UIElement.Measure(Graphics, Size)
- UIElement.MeasureOverride(Graphics, Size)
- UIElement.OnClick(MouseEventArgs)
- UIElement.OnDoubleClick(MouseEventArgs)
- UIElement.OnMouseDown(MouseEventArgs)
- UIElement.OnMouseEnter(MouseEventArgs)
- UIElement.OnMouseHover(MouseEventArgs)
- UIElement.OnMouseLeave(MouseEventArgs)
- UIElement.OnMouseMove(MouseEventArgs)
- UIElement.OnMouseUp(MouseEventArgs)
- UIElement.OnMouseWheel(MouseEventArgs)
- UIElement.OnRenderChildElements(PaintEventArgs)
- UIElement.OnResize(EventArgs)
- UIElement.PostArrangeOverride()
- UIElement.ReleaseMouseCapture()
- UIElement.Render(PaintEventArgs)
- UIElement.TransformToAncestor(IUIElement)
- UIElement.TransformToDescendant(IUIElement)
- UIElement.UpdateLayout()
- UIElement.IInputElement.IsMouseDirectlyOver
- UIElement.IUIElement.Visibility
- UIElement.ActualHeight
- UIElement.ActualWidth
- UIElement.Bounds
- UIElement.CaptureMouseWhenPressed
- UIElement.ClipBounds
- UIElement.DesiredSize
- UIElement.InvalidateOnMouseEvents
- UIElement.IsArrangeValid
- UIElement.IsMeasureValid
- UIElement.IsMouseCaptured
- UIElement.IsRightToLeft
- UIElement.Size
- UIElement.VisualOffset
- UIElement.Click
- UIElement.DoubleClick
- UIElement.MouseDown
- UIElement.MouseEnter
- UIElement.MouseHover
- UIElement.MouseLeave
- UIElement.MouseMove
- UIElement.MouseUp
- UIElement.MouseWheel
- UIElement.Resize
- LogicalTreeNodeBase.ILogicalTreeNode.FindAncestor(Type)
- LogicalTreeNodeBase.ILogicalTreeNode.GetCommonAncestor(ILogicalTreeNode)
- LogicalTreeNodeBase.ILogicalTreeNode.IsAncestorOf(ILogicalTreeNode)
- LogicalTreeNodeBase.ILogicalTreeNode.IsDescendantOf(ILogicalTreeNode)
- LogicalTreeNodeBase.CreateChildren()
- LogicalTreeNodeBase.OnParentChanged()
- LogicalTreeNodeBase.ILogicalTreeNode.Children
- LogicalTreeNodeBase.ILogicalTreeNode.Parent
- DisposableObject.Dispose()
- DisposableObject.VerifyNotDisposed()
- DisposableObject.IsDisposed
- DisposableObject.Disposed
- MarshalByRefObject.MemberwiseClone(Boolean)
- MarshalByRefObject.GetLifetimeService()
- MarshalByRefObject.InitializeLifetimeService()
- MarshalByRefObject.CreateObjRef(Type)
- Object.ToString()
- Object.Equals(Object)
- Object.Equals(Object, Object)
- Object.ReferenceEquals(Object, Object)
- Object.GetHashCode()
- Object.GetType()
- Object.MemberwiseClone()