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

Save Chart Image address in GUI

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

    Save Chart Image address in GUI

    Dear Support,

    I am developing a menu button indicator that would use the hot key for "Save Chart Image" and having difficulty to find the GUI substructure location for SaveChartImage. Would you kindly advise on the correct Content in the following example:

    Code:
    btn = new System.Windows.Controls.Button { Content = NinjaTrader.Gui.[B][COLOR=#FF0000]..................[/COLOR][/B].SaveChartImage };
    Many thanks.
    Last edited by aligator; 05-21-2020, 01:31 PM.

    #2
    Hello aligator,

    Are you trying to load the image as the buttons content? The SaveChartImage is a method that does not return anything. If you are just trying to call the method to open the save dialog you could do that in the following way in the buttons click event:

    Code:
    ChartControl.Dispatcher.InvokeAsync(() =>
    {
             Chart chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;
              chartWindow.Dispatcher.InvokeAsync(() =>
              {
                     chartWindow.SaveChartImage();
              });
    });

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello aligator,

      Are you trying to load the image as the buttons content? The SaveChartImage is a method that does not return anything. If you are just trying to call the method to open the save dialog you could do that in the following way in the buttons click event:

      Code:
      ChartControl.Dispatcher.InvokeAsync(() =>
      {
      Chart chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;
      chartWindow.Dispatcher.InvokeAsync(() =>
      {
      chartWindow.SaveChartImage();
      });
      });

      I look forward to being of further assistance.
      Thanks Jesse,

      I am creating a toolbar button that when clicked it will open the File Explorer asking for a location to save the image. Clicking the button is the same as clicking the Alt+S Hot Key for save chart image. So I am looking for the content to be used in the example I provided in post #1.

      This will be an additional button for my A mahToolBar indicator in Users Apps.

      Thanks.
      Last edited by aligator; 05-21-2020, 12:17 PM.

      Comment


        #4
        Hello aligator,

        Are you trying to load the Image that was saved as the buttons content? I am not certain what you are asking here based on the sample you provided.

        The Content of the button would be to hold Text or another control as a GUI element. The sample you provided does not really make sense because Content would not be used for holding an action or command, it would be for some content you want to present before the button is pressed. You could modify the buttons content later to be something else if you wanted to but that would have to be something that can actually be used as content like a string or a icon.

        Are you asking how to link the buttons action to invoke the command alt+s invokes?



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          [QUOTE=NinjaTrader_Jesse;n1101016]Hello aligator,

          Are you trying to load the Image that was saved as the buttons content? I am not certain what you are asking here based on the sample you provided.

          The Content of the button would be to hold Text or another control as a GUI element. The sample you provided does not really make sense because Content would not be used for holding an action or command, it would be for some content you want to present before the button is pressed. You could modify the buttons content later to be something else if you wanted to but that would have to be something that can actually be used as content like a string or a icon.

          Are you asking how to link the buttons action to invoke the command alt+s invokes?



          I look forward to being of further assistance.
          [QUOTE]

          Yes, thanks for the right words.

          I actually want to link a new toolbar button action to invoke the command alt+S invoke and are not using an Icon but text. Here is what I am adding to A mahToolBar indiator in User Apps. The button(text) installs but clicking will do nothing.

          Code:
          // Creating a Style for Text, Invoke and SendKeys
          Style btnStyle = new Style();
          btnStyle.TargetType = typeof(System.Windows.Controls.Button);
          
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontSizeProp erty, 22.0));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontFamilyPr operty, new FontFamily("Webdings")));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontWeightPr operty, FontWeights.Normal));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.MarginProper ty, new Thickness(2, 0, 2, 0)));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.PaddingPrope rty, new Thickness(0, 0, 0, 0)));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.ForegroundPr operty, Brushes.Gold));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.BackgroundPr operty, Brushes.Transparent));
          btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.IsEnabledPro perty, true));
          .
          .
          .
          .
          if(chartWindow != null)
          {
          ChartControl.Dispatcher.InvokeAsync ((Action)(() =>
          {
          
          if (btnSaveChartImage != null)
          {
          chartWindow.MainMenu.Remove(btnSaveChartImage);
          btnSaveChartImage = null;
          }
          }}
          .
          .
          .
          private void btnSaveChartImage_Click(object sender, EventArgs e)
          {
          SendKeys.SendWait("%{S}"); //Hot key assigned: Alt + S
          }
          Last edited by aligator; 05-21-2020, 01:30 PM.

          Comment


            #6
            Hello aligator,

            Thanks for clarifying that.

            If you want to invoke the command there are a couple of ways to do that.

            For any commands which are in the ChartCommands class you can just assign your buttons command directly to that:
            Code:
            Button b = new Button() {  Command = ChartCommands.SaveChartImage };
            There are commands for the drawing objects which you may want to use as well.

            ChartDrawingToolCommands.AndrewsPitchfork as an example. You can use visual studio and type Command to get a list of objects which have Commands for NinjaScript tasks.


            The alternative is what I already posted, you would put this in your button click event:

            Code:
            private void btnSaveChartImage_Click(object sender, EventArgs e)
            { 
             ChartControl.Dispatcher.InvokeAsync(() => {          Chart chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;           chartWindow.Dispatcher.InvokeAsync(() =>           {                  chartWindow.SaveChartImage();           }); }); 
            }

            Also a note on SendKeys, that is no longer used because it does not deal with WPF focus correctly. I would suggest when you have some time to review what is being done in the Rollover Indications indicator and how that sends keys to a control directly. If you plan to send keys that takes into account the focus which helps to make sure it always works.

            Shows a button on the chart to roll the expiry to the next available contract month. Option to hide button until a number of days before or on roll date. Another option to confirm by opening the instrument overlay selector or automatically rollover without confirmation. (Update June 27th, 2019 – Added an option to show […]



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello aligator,

              Thanks for clarifying that.

              If you want to invoke the command there are a couple of ways to do that.

              For any commands which are in the ChartCommands class you can just assign your buttons command directly to that:
              Code:
              Button b = new Button() { Command = ChartCommands.SaveChartImage };
              Thank you so much Jesse, you make it look so simple. I just added your Comand code as following and works like a charm. Another lesson how on to work with chart commands.

              Code:
              btn = new System.Windows.Controls.Button { Command = ChartCommands.SaveChartImage };
              Also, I am familiar with i.e. Gui.Tools.Icons.DrawAndrewsPitchfork = Content, and have used it in my ToolBar. But ChartDrawingToolCommands is new to me and opens many customization projects.

              Thank a bunch.

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello aligator,

                Thanks for clarifying that.

                If you want to invoke the command there are a couple of ways to do that.

                For any commands which are in the ChartCommands class you can just assign your buttons command directly to that:
                Code:
                Button b = new Button() { Command = ChartCommands.SaveChartImage };
                I look forward to being of further assistance.
                Thank you Jesse,

                As I indicated in my last post, Command worked perfectly for a SaveChartImage button.

                Also, I am trying to create another button to switch between chart templates and link the button action to invoke a hot key (alt +T) for Templates/Load. However the Template/Load is not a chart command and while the button is created the hot key will not be invoked.

                Would you please comment on an alternative to Command statement in the following code so that a Templates/Load hot key can be invoked?

                Code:
                 
                 btn = new System.Windows.Controls.Button { Command = ChartCommands.SaveChartImage };
                Many thanks.



                Comment


                  #9
                  Hello aligator,

                  I took a look through the commands that I could locate in visual studio but was unable to see anything relating to templates. This may be a situation where you instead need to invoke the keyboard shortcut against the chart control if you are trying to automate that in some way. This part of the code is very likely just a part of the overall chart code rather than being an exposed Command like the others.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by morrnel, Today, 06:07 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by thumper57, Yesterday, 04:30 PM
                  6 responses
                  20 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by sastrades, 05-10-2024, 09:59 AM
                  3 responses
                  55 views
                  0 likes
                  Last Post rc5781
                  by rc5781
                   
                  Started by guyonabuffalo, Yesterday, 10:01 PM
                  2 responses
                  22 views
                  0 likes
                  Last Post guyonabuffalo  
                  Started by reynoldsn, 05-10-2024, 07:04 PM
                  5 responses
                  27 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X