Back to Devexpress

ImageAnnotation.SizeMode Property

corelibraries-devexpress-dot-xtracharts-dot-imageannotation.md

latest11.9 KB
Original Source

ImageAnnotation.SizeMode Property

Specifies the image size mode for the annotation.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public ChartImageSizeMode SizeMode { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property SizeMode As ChartImageSizeMode

Property Value

TypeDescription
ChartImageSizeMode

A ChartImageSizeMode enumeration value that represents the annotation’s image size mode.

|

Available values:

NameDescription
AutoSize

Represents the size mode, in which an image is auto-resized to fit its container’s bounds.

| | Stretch |

Represents the size mode, in which an image is stretched to fit its container’s bounds.

| | Zoom |

Represents the size mode, in which an image is zoomed to fit its container’s bounds.

| | Tile |

Represents the size mode, in which an image is tiled to fit its container’s bounds.

|

Remarks

When the SizeMode property is set to AutoSize , the annotation is auto-resized to fit the image it contains.

When the SizeMode property is set to any value other than AutoSize , the annotation’s bounds are determined by its Annotation.Height and Annotation.Width properties.

To control the dimensions of text annotations, use the TextAnnotation.AutoSize property.

Example

The following example demonstrates how to create text and image annotations and anchor them to a chart, its pane, and a series point.

View Example

cs
#region #usings
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using DevExpress.Drawing;
using DevExpress.XtraCharts;
// ...
#endregion #usings

namespace AnnotationsSample {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        #region #generalcode
        private void Form1_Load(object sender, EventArgs e) {
            // Add a text annotation to the chart control's repository.
            chartControl1.AnnotationRepository.Add(new TextAnnotation("Annotation 1"));

            // And, assign a series point to the annotation's AnchorPoint property.
            // This adds the annotation to the series point's Annotations collection.
            chartControl1.AnnotationRepository[0].AnchorPoint =
                new SeriesPointAnchorPoint(chartControl1.Series[0].Points[2]);

            // Now, create an image annotation, and add it to the chart's collection.
            chartControl1.Annotations.AddImageAnnotation("Annotation 2",
                DXImage.FromStream(new FileStream(@"...\...\image.png", FileMode.Open, FileAccess.Read, FileShare.Read)));

            // Define the X and Y absolute coordinates for the annotation, in pixels.
            ((ChartAnchorPoint)chartControl1.Annotations[0].AnchorPoint).X = 150;
            ((ChartAnchorPoint)chartControl1.Annotations[0].AnchorPoint).Y = 150;

            // Obtain the additional pane from the diagram's collection.
            XYDiagramPaneBase myPane = ((XYDiagram)chartControl1.Diagram).Panes[0];

            // And, position the chart's annotation in this pane's right top corner;
            ((FreePosition)chartControl1.Annotations[0].ShapePosition).DockTarget = myPane;
            ((FreePosition)chartControl1.Annotations[0].ShapePosition).DockCorner = DockCorner.RightTop;

            // Another annotation is now being added to the collection of this pane.
            myPane.Annotations.AddImageAnnotation("Annotation 3",
                DXImage.FromStream(new FileStream(@"...\...\image.png", FileMode.Open, FileAccess.Read, FileShare.Read)));

            // Define its axis coordinates (in units appropriate for the scale type of the axes).
            ((PaneAnchorPoint)myPane.Annotations[0].AnchorPoint).AxisXCoordinate.AxisValue = 2;
            ((PaneAnchorPoint)myPane.Annotations[0].AnchorPoint).AxisYCoordinate.AxisValue = 180;

            // Position the annotation in relation to its anchor point.
            ((RelativePosition)myPane.Annotations[0].ShapePosition).Angle = -135;
            ((RelativePosition)myPane.Annotations[0].ShapePosition).ConnectorLength = 50;

            // You can get an annotation either via the collection of the element to which it is anchored,
            // or centrally, via the chart control's repository (e.g. by its name).
            TextAnnotation myTextAnnotation =
                (TextAnnotation)chartControl1.AnnotationRepository.GetElementByName("Annotation 1");
            ImageAnnotation myImageAnnotation =
                (ImageAnnotation)chartControl1.AnnotationRepository.GetElementByName("Annotation 3");

            // Define the text for the text annotation.
            myTextAnnotation.Text = "<i>Basic</i> <b>HTML</b> <u>is</u> <color=blue>supported</color>.";

            // Enable the interactive positioning for the image annotation.
            myImageAnnotation.RuntimeMoving = true;
            myImageAnnotation.RuntimeAnchoring = true;
            myImageAnnotation.RuntimeResizing = true;
            myImageAnnotation.RuntimeRotation = true;

            // Specify image annotation size mode.
            myImageAnnotation.SizeMode = ChartImageSizeMode.Tile;

            // And, adjust image annotation appearance options.
            myImageAnnotation.ShapeKind = ShapeKind.RoundedRectangle;
            myImageAnnotation.ShapeFillet = 10;
            myImageAnnotation.ConnectorStyle = AnnotationConnectorStyle.Arrow;
        }
        #endregion #generalcode

    }
}
vb
#Region "#usings"
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Imports DevExpress.Drawing
Imports DevExpress.XtraCharts

' ...
#End Region ' #usings
Namespace AnnotationsSample

    Public Partial Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

#Region "#generalcode"
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Add a text annotation to the chart control's repository.
            chartControl1.AnnotationRepository.Add(New TextAnnotation("Annotation 1"))
            ' And, assign a series point to the annotation's AnchorPoint property.
            ' This adds the annotation to the series point's Annotations collection.
            chartControl1.AnnotationRepository(0).AnchorPoint = New SeriesPointAnchorPoint(chartControl1.Series(0).Points(2))
            ' Now, create an image annotation, and add it to the chart's collection.
            chartControl1.Annotations.AddImageAnnotation("Annotation 2", DXImage.FromStream(New FileStream("...\...\image.png", FileMode.Open, FileAccess.Read, FileShare.Read)))
            ' Define the X and Y absolute coordinates for the annotation, in pixels.
            CType(chartControl1.Annotations(0).AnchorPoint, ChartAnchorPoint).X = 150
            CType(chartControl1.Annotations(0).AnchorPoint, ChartAnchorPoint).Y = 150
            ' Obtain the additional pane from the diagram's collection.
            Dim myPane As XYDiagramPaneBase = CType(chartControl1.Diagram, XYDiagram).Panes(0)
            ' And, position the chart's annotation in this pane's right top corner;
            CType(chartControl1.Annotations(0).ShapePosition, FreePosition).DockTarget = myPane
            CType(chartControl1.Annotations(0).ShapePosition, FreePosition).DockCorner = DockCorner.RightTop
            ' Another annotation is now being added to the collection of this pane.
            myPane.Annotations.AddImageAnnotation("Annotation 3", DXImage.FromStream(New FileStream("...\...\image.png", FileMode.Open, FileAccess.Read, FileShare.Read)))
            ' Define its axis coordinates (in units appropriate for the scale type of the axes).
            CType(myPane.Annotations(0).AnchorPoint, PaneAnchorPoint).AxisXCoordinate.AxisValue = 2
            CType(myPane.Annotations(0).AnchorPoint, PaneAnchorPoint).AxisYCoordinate.AxisValue = 180
            ' Position the annotation in relation to its anchor point.
            CType(myPane.Annotations(0).ShapePosition, RelativePosition).Angle = -135
            CType(myPane.Annotations(0).ShapePosition, RelativePosition).ConnectorLength = 50
            ' You can get an annotation either via the collection of the element to which it is anchored,
            ' or centrally, via the chart control's repository (e.g. by its name).
            Dim myTextAnnotation As TextAnnotation = CType(chartControl1.AnnotationRepository.GetElementByName("Annotation 1"), TextAnnotation)
            Dim myImageAnnotation As ImageAnnotation = CType(chartControl1.AnnotationRepository.GetElementByName("Annotation 3"), ImageAnnotation)
            ' Define the text for the text annotation.
            myTextAnnotation.Text = "<i>Basic</i> <b>HTML</b> <u>is</u> <color=blue>supported</color>."
            ' Enable the interactive positioning for the image annotation.
            myImageAnnotation.RuntimeMoving = True
            myImageAnnotation.RuntimeAnchoring = True
            myImageAnnotation.RuntimeResizing = True
            myImageAnnotation.RuntimeRotation = True
            ' Specify image annotation size mode.
            myImageAnnotation.SizeMode = ChartImageSizeMode.Tile
            ' And, adjust image annotation appearance options.
            myImageAnnotation.ShapeKind = ShapeKind.RoundedRectangle
            myImageAnnotation.ShapeFillet = 10
            myImageAnnotation.ConnectorStyle = AnnotationConnectorStyle.Arrow
        End Sub
#End Region ' #generalcode
    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SizeMode property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-chart-accompany-chart-elements-by-text-or-image-annotations/VB/AnnotationsSample/Form1.vb#L57

vb
' Specify image annotation size mode.
myImageAnnotation.SizeMode = ChartImageSizeMode.Tile
' And, adjust image annotation appearance options.

See Also

ImageAnnotation Class

ImageAnnotation Members

DevExpress.XtraCharts Namespace