• 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

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.

          https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

          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.

            https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

            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 Rmos22, Today, 02:20 PM
              0 responses
              1 view
              0 likes
              Last Post Rmos22
              by Rmos22
               
              Started by sawtooth500, Today, 12:59 PM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Spencer  
              Started by Steve L, Yesterday, 09:36 PM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by MichaelAlexander, 04-25-2017, 03:28 AM
              9 responses
              1,170 views
              0 likes
              Last Post dani neira  
              Started by uday12, Today, 11:34 AM
              2 responses
              9 views
              0 likes
              Last Post uday12
              by uday12
               
              Working...
              X