Skip to main content
A newer version of this page is available. .

CrosshairLineElement Class

Defines the appearance of a crosshair argument line and crosshair value line elements when custom drawing a crosshair cursor using the ChartControl.CustomDrawCrosshair event.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v21.2.dll

NuGet Package: DevExpress.Charts

Declaration

[RuntimeObject]
public class CrosshairLineElement

The following members return CrosshairLineElement objects:

Remarks

To get access to the appearance properties of the CrosshairLineElement object, use the CrosshairElementBase.LineElement property when dealing with crosshair value lines and the CustomDrawCrosshairEventArgs.CrosshairLineElement property for the crosshair argument line if the CrosshairOptions.SnapMode property is set to NearestArgument.

When the CrosshairOptions.SnapMode is set to NearestValue, these properties will affect other crosshair line elements. For instance, the CustomDrawCrosshairEventArgs.CrosshairLineElement property will change the appearance of crosshair value lines.

For more information on crosshair cursors, see Tooltip and Crosshair Cursor.

Example

This example shows how to use the ChartControl.CustomDrawCrosshair event to provide a custom appearance for the crosshair cursor. This event is invoked when you select the Custom Draw Crosshair Cursor check box.

If you wish to display crosshair axis lines and labels on a chart before custom drawing the crosshair cursor, set the CrosshairOptions.ShowArgumentLine, CrosshairOptions.ShowArgumentLabels, CrosshairOptions.ShowValueLabels and CrosshairOptions.ShowValueLine properties to true.

Note that the crosshair cursor customization is provided for the CrosshairOptions.SnapMode property set to NearestArgument.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace CustomDrawCrosshairCursor {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void OnCheckEditCheckedChanged(object sender, EventArgs e) {
            if (checkEdit1.Checked)
                chartControl1.CustomDrawCrosshair += OnChartControlCustomDrawCrosshair;
            else 
                chartControl1.CustomDrawCrosshair -= OnChartControlCustomDrawCrosshair;               
        }

        private void OnChartControlCustomDrawCrosshair(object sender, CustomDrawCrosshairEventArgs e) {
            // Specify the crosshair argument line color, dash style and thickness.
            e.CrosshairLineElement.Color = Color.Green;
            e.CrosshairLineElement.LineStyle.DashStyle = DashStyle.DashDot;
            e.CrosshairLineElement.LineStyle.Thickness = 3;

            // Specify the back color for the crosshair argument axis label. 
            foreach (CrosshairAxisLabelElement axisLabelElement in e.CrosshairAxisLabelElements)
                axisLabelElement.BackColor = Color.Blue;

            foreach (CrosshairElementGroup group in e.CrosshairElementGroups) {
                CrosshairGroupHeaderElement groupHeaderElement = group.HeaderElement;

                // Specify the text, text color and font for the crosshair group header element. 
                groupHeaderElement.Text = "Custom draw";
                groupHeaderElement.TextColor = Color.Green;
                groupHeaderElement.Font = new Font(this.Font, FontStyle.Bold);

                // Obtain a crosshair element for the first series.
                CrosshairElement element = group.CrosshairElements[0];

                // Specify the color, dash style and thickness for the crosshair value lines. 
                element.LineElement.Color = Color.DarkViolet;
                element.LineElement.LineStyle.DashStyle = DashStyle.Dash;
                element.LineElement.LineStyle.Thickness = 2;

                // Specify the text color and back color for the crosshair value labels.
                element.AxisLabelElement.TextColor = Color.Red;
                element.AxisLabelElement.BackColor = Color.Yellow;

                // Format the text shown for the series in the crosshair cursor label. Specify the text color and marker size. 
                element.LabelElement.TextColor = Color.Red;
                element.LabelElement.MarkerSize = new Size(15, 15);
                element.LabelElement.Text = string.Format("{0}: A={1}; V={2}", element.Series.Name, element.SeriesPoint.Argument, element.SeriesPoint.Values[0]);
            }
        }
    }
}

Inheritance

Object
CrosshairLineElement
See Also