IsSelected

View as Markdown

Definition

Indicates a chart object is currently selected. When this property is set to true in a DrawingTool, the GetSelectionPoints() will be called.

Property Value

This property returns true to indicate that the chart object is selected; otherwise, false. Default set to false.

This property value is ONLY guaranteed to be settable by the object to which it belongs (e.g., from within a DrawingTool). Modifying its value from an external object (such as attempting to set a DrawingTool.IsSelected from an indicator) can result in the property automatically returning the value handled by its source. In other words, unless you are working with a chart object type directly (e.g., building a custom drawing tool), the IsSelected property should be considered read-only.

Syntax

IsSelected

Examples

Reading the IsSelected property from an indicator

1protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
2{
3 foreach(DrawingTool drawTool in DrawObjects)
4 {
5 // only apply logic below to types of "Rectangle")
6 if(drawTool.GetType().ToString().Contains("Rectangle"))
7 {
8 // safely cast as dynamic type at run-time
9 dynamic myRect = drawTool;
10
11 // Changes the brush to pink to indicating selected
12 if(drawTool.IsSelected)
13 {
14 myRect.AreaBrush = Brushes.Pink;
15 }
16 // otherwise, set back to default value on next render pass
17 else myRect.AreaBrush = Brushes.CornflowerBlue;
18 }
19 }
20}

Explicitly setting the IsSelected property from a DrawingTool type

1public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
2{
3 if(DrawingState == DrawingState.Building)
4 {
5 if(dataPoint.IsEditing)
6 {
7 // do something
8 }
9
10 // when done editing anchor, set the state to normal and unselect the drawing object
11 else if(dataPoint.IsEditing)
12 {
13 DrawingState = DrawingState.Normal;
14 IsSelected = false;
15 }
16 }
17
18}