• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Capture chart mouse events from Add-On

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Capture chart mouse events from Add-On

    I am wondering how an Add-On could capture mouse events (down, move, up) for a specific chart? For example, similar to a drawing tool, once add-on activated, capture the mouse events, and then once an action is completed stop capturing and let them flow back to the chart.

    #2
    Hello aslane,

    Thanks for the post.

    The ChartControl object has the MouseDownPoint property which will give you the (x,y) coordinates of the left mouse button whenever it is clicked or held.
    There are mouse events built into C#, so you can use them in your chart panel, ChartControl, or TabControl.

    There is an example of how to use MouseDownPoint on this help guide page:
    https://ninjatrader.com/support/help...edownpoint.htm

    Here is how to use Windows WPF controls, I am building this off of the AddOnFramework example.

    Whenever you create your NTWindow or TabPage, subscribe your mouse event function in the constructor like so:

    ... denotes that I have left out code.

    Code:
    public class AddOnFrameworkWindow : NTWindow, IWorkspacePersistence
    	{
    		public AddOnFrameworkWindow()
    		{
    			
    			Caption = "AddOn Framework";
    
    			// Set the default dimensions of the window
    			Width = 1085;
    			Height = 900;
    
    			
    			TabControl tc = new TabControl();
    
                            tc.MouseLeftButtonDown += OnMouseDown;
                             
                            ...
    Then implement your event function underneath the constructor, still within the class:

    Code:
    public class AddOnFrameworkWindow : NTWindow, IWorkspacePersistence
    	{
    		public AddOnFrameworkWindow()
    		{
                            ...
                            tc.MouseLeftButtonDown += OnMouseDown;
    
                            ...
    		}
    
            public void OnMouseDown(object sender, MouseEventArgs e) {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                      MessageBox.Show("The Left Mouse Button is pressed");
                 }
            }
            ...
    Please see the following links for more information:
    https://ninjatrader.com/support/help...page_class.htm - NTTabPage Class
    https://ninjatrader.com/support/help.../?ntwindow.htm - NTWindow
    https://ninjatrader.com/support/help...chartpanel.htm - ChartPanel
    https://ninjatrader.com/support/help...artcontrol.htm - Chart Control
    https://ninjatrader.com/support/help...edownpoint.htm - MouseDownPoint

    Here are some publicly available links on C# mouse event handling:
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx - MouseEventArgs
    https://docs.microsoft.com/en-us/dot...input-overview - WPF Input overview.

    Here is a link to the AddonFramework Visual Studio solution example, click on the link titled "Download Visual Studio Solution for AddOn Development":
    https://ninjatrader.com/support/help...t_overview.htm

    Please let us know if we may be of further assistance.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Andreas189, Today, 10:28 AM
    2 responses
    3 views
    0 likes
    Last Post Andreas189  
    Started by faisamtrader, Today, 09:30 AM
    2 responses
    9 views
    0 likes
    Last Post faisamtrader  
    Started by CDXTrader, Today, 12:29 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by YevhenShynkarenko, Today, 08:14 AM
    0 responses
    3 views
    0 likes
    Last Post YevhenShynkarenko  
    Started by YevhenShynkarenko, Today, 07:14 AM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Jim  
    Working...
    X