I'm trying to delete manually drawn objects from an indicator. (I'm aware that is unsupported etc.). My goal is to remove the currently selected draw object by simulating a delete key input when pressing a button (it's for when a keyboard is not present). There is only one thing I'm struggling with. When the button is pressed, the focus is on the button in the chart trader area, thus the delete key doesn't remove the draw object. Is there some way to set the focus back to the selected draw object? For the time being I thought of simulating a mouse click onto the draw object, but only found that the pixel coordinates seem to be off. My current method is:
var point = draw.GetSelectionPoints(ChartControl, myChartScale)[0]; int x = ChartingExtensions.ConvertToHorizontalPixels(point.X, ChartControl.PresentationSource); int y = ChartingExtensions.ConvertToVerticalPixels(point.Y, ChartControl.PresentationSource); MouseSimulator.SetMousePosition(x,y); MouseSimulator.LeftMouseClick(x, y); Keyboard.FocusedElement.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(ChartControl.OwnerChart), 0, Key.Delete) { RoutedEvent = Keyboard.PreviewKeyDownEvent } );
Also, I'd like to know if there's a way to identify the currently selected snap mode and change it? I can simulate hotkey events for changing it if that's not possible through code, but I still need some way to identify it.
Comment