Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Craeting Buttons g

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

    Craeting Buttons g

    Dear Support,

    I can create a one-click drawing tool button for a default Ninja Drawing Tool using a default Ninja Icons, no problem. For example, for Ninja default DrawRay I define the button using default Icons as:

    Code:
    				if (!isToolBarButtonAdded && showRay)
    				{
    				btnRay = new System.Windows.Controls.Button { Content = NinjaTrader.Gui.Tools.Icons.DrawRay, };
    				btnRay.Click += btnRay_Click;
    				chartWindow.MainMenu.Add(btnRay);
    				}
    And this work perfect.

    However, If I use a text symbol instead of an Icon I must create a style to apply per Help information. Therefore, for using a Wingdings 3 font symbol I change the above script to:

    Code:
    				if (!isToolBarButtonAdded && showRay) 
    				{
    				Style btnStyle = new Style();
    		        btnStyle.TargetType = typeof(System.Windows.Controls.Button);
    
    		        btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontSizeProperty, 24.0));
    		        btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontFamilyProperty, new FontFamily("Wingdings 3")));
    		        btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontWeightProperty, FontWeights.Bold));
    				
    				btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.ForegroundProperty, Brushes.CornflowerBlue));
    				btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.BackgroundProperty, Brushes.Transparent));
    				btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.IsEnabledProperty, true));
    
    				btnRay = new System.Windows.Controls.Button { Content = "*", Style = btnStyle, }; // "*" is the keyboard key for drawing symbol from the FontFamily 
    				btnRay.Click += btnHorizontalRay_Click;
    				chartWindow.MainMenu.Add(btnRay);
    				}
    Everything else in the script being equal, this modification will implement a button successfully with a font character.

    However, the issue I have is the button will not get activated by a mouse click.

    I followed the "Using BitmapImage objects with Buttons" in Help section. Also, using padding and margin properties did not make a difference.

    Am I missing anything?

    Many thanks.
    Last edited by aligator; 08-08-2018, 10:06 AM.

    #2
    Hello aligator,

    Thanks for the note.

    I was able to get your code to work by placing it inside of the mahToolbar indicator. It seems like there is something wrong with your button click function since the code that you posted works with the btnRay_Click function in mahtoolbar. I have attached the modified indicator for your review.

    Please let me know if I can assist further.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello aligator,

      Thanks for the note.

      I was able to get your code to work by placing it inside of the mahToolbar indicator. It seems like there is something wrong with your button click function since the code that you posted works with the btnRay_Click function in mahtoolbar. I have attached the modified indicator for your review.

      Please let me know if I can assist further.
      Thanks Chris,

      Actually, I was creating this button for a custom Draw Tool, "HorizontalRay" that is installed under the Tools and works fine on its own. I am trying to make it part of the mahToolBar2 butttons and post a revised mahToolBar in the forum.

      The only other parts of the script similar to other default Icons script for the click functions are:

      Code:
      		private System.Windows.Controls.Button btnHorizontalRay = new System.Windows.Controls.Button();
      Code:
      		if (btnHorizontalRay != null)
      		{
      			Dispatcher.Invoke((Action)(() =>
      			{
      				chartWindow.MainMenu.Remove(btnHorizontalRay);						
      				btnHorizontalRay.Click -= btnHorizontalRay_Click;
      				btnHorizontalRay = null;
      			}));
      					}
      Code:
      		private void btnHorizontalRay_Click(object sender, EventArgs e)
      		{
      			SendKeys.SendWait("^{Left}");
      		}

      The "^{Left}" is the HotKey I created for this custom draw tool.

      Any idea where the click function issue might be? Does the first piece of code define the button correctly?


      Thanks a bunch!
      Last edited by aligator; 08-07-2018, 01:38 PM.

      Comment


        #4
        Hello aligator,

        Thanks for the reply.

        It looks like button combos will not allow the click to occur. I tried using the same hotkey and get the same result. I will inquire with our product management team to see if that would be expected.

        Edit: I see other drawing tool using button combo hotkeys, yet setting up the ray as a combo hotkey does not work in the script. The trend channel works no problem. I also noticed that the chart marker buttons will not work either.

        Thanks in advance for your patience.
        Last edited by NinjaTrader_ChrisL; 08-07-2018, 02:44 PM.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello alligator,

          Thanks for your patience. Since the SendKeys.SendWait is not a supported NinjaScript method, I am unable to profile the code any further. The help page on the method has a somewhat vague description of the method being susceptible to timing issues.



          It is possible that this is what you are running into. Some additional debugging will need to be done to know what is going on with the SendKeys class.

          Please let me know if I can assist further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChrisL View Post
            Hello alligator,

            Thanks for your patience. Since the SendKeys.SendWait is not a supported NinjaScript method, I am unable to profile the code any further. The help page on the method has a somewhat vague description of the method being susceptible to timing issues.



            It is possible that this is what you are running into. Some additional debugging will need to be done to know what is going on with the SendKeys class.

            Please let me know if I can assist further.
            Thank you ChrisL,

            What is (if any) the Ninja supported method to use instead of SendKeys.SendWait in the following script

            Code:
            		private void btnHorizontalRay_Click(object sender, EventArgs e)
            		{
            			SendKeys.SendWait("^{Left}");
            		}

            I believe, if I am not wrong, the SendKeys.SendWait method was suggested in a snipet by ChelseaB sometimes ago.

            Many Thanks.
            Last edited by aligator; 08-09-2018, 11:58 AM.

            Comment


              #7
              Hello aligator,

              Thanks for the reply.

              There is no supported method to interact with the user interface in this way. When you click the button, the chart is losing focus, so you are sending the key to the button. Is seems like the way to fix this would be to find an alternative to SendKeys. You can use code like this to invoke a drawing tool:
              Code:
              ChartDrawingToolCommands.Ray.Execute(null);
              Please let me know if i can assist further.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kujista, Today, 05:44 AM
              0 responses
              5 views
              0 likes
              Last Post kujista
              by kujista
               
              Started by ZenCortexCLICK, Today, 04:58 AM
              0 responses
              5 views
              0 likes
              Last Post ZenCortexCLICK  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              172 responses
              2,281 views
              0 likes
              Last Post sidlercom80  
              Started by Irukandji, Yesterday, 02:53 AM
              2 responses
              18 views
              0 likes
              Last Post Irukandji  
              Started by adeelshahzad, Today, 03:54 AM
              0 responses
              8 views
              0 likes
              Last Post adeelshahzad  
              Working...
              X