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

Two tabs print to one outputBox

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

    Two tabs print to one outputBox

    Hi, my AddOn contains two different Tabs: one for the tradingsystem and a second for maintenance.

    The tradingsystem-tab has the outputBox.
    If i want the maintenance-tab to write text to the outputBox of the tradingsystem-tab, how to do that ??

    I tried the following:

    At the tradingsystem-tab i've changed the outputBox to public:
    Code:
    public TextBox outputBox
            {
                get; set;
            }
    and at the maintenance-tab:
    Code:
    TradingSystemTab tradingSystemTab = new TradingSystemTab();
    tradingSystemTab.outputBox.Text = "TestText";
    but its not printing "TestText" to the outputBox.

    What is the problem here ??

    Thanks, GoS

    #2
    Hi GoS,

    I'm not understanding what you are trying to do.

    Are you creating your own wpf text box and attempting to added text to this?

    What code have you used to create the text box?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      I'm really far from knowing that I can do it myself so i have used the AddOnFramework-sample and some ohter NT-AddOn-samples as base to create my addon.

      Now, the first tab which contains the outputbox runs out of space and i decided to expand to a second tab. I have added a second tab. This is the code from the window-constructor:
      Code:
      // Constructor:
              public TradingSystemWindow()
              {
                  Caption = "TradingSystem";
      
                  Width = 1085;
                  Height = 900;
      
                  // Sets the window start behaviour to start maximized.
                  this.WindowState = WindowState.Maximized;
      
                  // TabControl should be created for window content if tab features are wanted.
                  TabControl tabControl = new TabControl();
                  TabControlManager.SetIsMovable(tabControl, false);
                  TabControlManager.SetCanAddTabs(tabControl, false);
                  TabControlManager.SetCanRemoveTabs(tabControl, false);
                  TabControlManager.SetFactory(tabControl, new TradingSystemFactory());
                  Content = tabControl;
                  tabControl.AddNTTabPage(new TradingSystemTab());
                  tabControl.AddNTTabPage(new MaintenanceTab());
      
                  Loaded += (o, e) =>
                  {
                      if (WorkspaceOptions == null)
                      {
                          WorkspaceOptions = new WorkspaceOptions("TradingSystemWindow" + Guid.NewGuid().ToString("N"), this);
                      }
                  };
              }
      The outputBox is at the TradingSystemTab:
      Code:
      public class TradingSystemTab : NTTabPage
          {
              public TextBox              outputBox { get; set; }
      
              // Constructor:
              public TradingSystemTab()
              {
                  Content = LoadXAML();
      
                  TabName = "TradingSystem";
              }
      
              private DependencyObject LoadXAML()
              {
                  try
                  {
                      using (FileStream fileStream = new FileStream(Path.Combine(Globals.UserDataDir, @"bin\Custom\AddOns\TradingSystem.xaml"), FileMode.Open))
                      {
                          if (fileStream == null)
                              return null;
      
                          Page page = XamlReader.Load(fileStream) as Page;
                          DependencyObject pageContent = null;
                          if (page != null)
                          {
                              pageContent = page.Content as DependencyObject;
      
                              // Find Output Box and set its FontFamily.
                              outputBox = LogicalTreeHelper.FindLogicalNode(pageContent, "outputBox") as TextBox;
                              outputBox.FontFamily = new FontFamily("Consolas");
                              outputBox.Text = "Output Box";
                          }
                      }
                  }
              }
          }
      What I am trying to do is to add text to this outputBox, but from the second tab:
      Code:
      public class MaintenanceTab : NTTabPage
          {
              TradingSystemTab tradingSystemTab = new TradingSystemTab();
              private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
      
              // Constructor:
              public MaintenanceTab()
              {
                  Content = LoadXAML();
      
                  TabName = "Maintenance";
      
                  timer.Tick += new EventHandler(OnTimer);
                  timer.Interval = 1000;
                  timer.Start();
              }
      
              public void OnTimer(object sender, EventArgs e)
              {
                  tradingSystemTab.outputBox.Text = "TestText";
              }
          ]
      The onTimer-event is only added for testing this.
      But the outputBox on TradinSystem-tab is not printing "TestText".

      What did i do wrong ??

      Thanks, GoS

      Comment


        #4
        Hello GoS,

        If I am understanding this correctly, the timer is created in the constructor of the MaintenanceTab and the timer is writing to a TextBox wpf object on the TradingSystemTab.

        Have you ensured the timer is working by printing to the output window?
        NinjaTrader.Code.Output.Process("my message", PrintTo.OutputTab1);


        Have you ensured that the TextBox was found and is not null?

        Are you getting any errors?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          yes this is correct,
          whereas at the moment the timer is only started to have some ability to test the writing to the TradingSystemTab's TextBox.
          In future, i will not use the timer, but all the messages (errormessages and so on) from MaintenanceTab should be written to this TradingSystemTab's textBox.

          I have ensured, the timer is working.
          And I have ensured the TextBox was found. All the messages from the TradingSystemTab where printed out correctly.

          I think, i have some problems on correct instancing from one class to another. I have tested to change the TradingSystemTab's Textbox to static:
          Code:
          public class TradingSystemTab : NTTabPage
              {
                  private static TextBox           outputBox;
                  public  static string              TextString
                  {
                      get
                      {
                          return outputBox.Text;
                      }
                      set
                      {
                          outputBox.Text = value;
                      }
                  }
          ...
          So i have not to get some new instance of the TradingSystemTab within the MaintenanceTab and i can directly access the TextString property:
          Code:
          public class MaintenanceTab : NTTabPage
              {
                  // This is not needed with the static TextString property
                  // TradingSystemTab tradingSystemTab = new TradingSystemTab();
                  
                  private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
          
                  // Constructor:
                  public MaintenanceTab()
                  {
                      Content = LoadXAML();
          
                      TabName = "Maintenance";
          
                      timer.Tick += new EventHandler(OnTimer);
                      timer.Interval = 1000;
                      timer.Start();
                  }
          
                  public void OnTimer(object sender, EventArgs e)
                  {
                      // Old code:
                      // tradingSystemTab.outputBox.Text = "TestText";
                      TradingSystemTab.TextString = "TestText" + DateTime.Now.ToString();
                  }
              }
          This is a way which is running. The textBox is printing every second the testtext.
          But this way is some ugly one. I would prefer some solution without a static textbox.

          Thanks, GoS

          Comment


            #6
            Hi GoS,

            Thanks for confirming that.

            It does appear that you create the instance of the tab page and add this to the tabControl.

            tabControl.AddNTTabPage(new TradingSystemTab());

            Then, from within the MaintenanceTab (that was also created and added to the tabControl) you make a second instance of a new tab page but this isn't added to anything and its never displayed. The TextBox in this created but never displayed instance is where you are writing the text.

            Instead, why not create a variable to hold the first instance of the TradingSystemTab and then add that variable to the tabControl. Then create a property within the MaintenanceTab class to hold the first instance of the TradingSystemTab, and then in the TradingSystemWindow() constructor set the property to that instance.

            Code:
            private TradingSystemTab tradingSystemTabInstance;
            private MaintenanceTab maintenanceTabInstance;
            public TradingSystemWindow()
            {
            tradingSystemTabInstance = new TradingSystemTab();
            
            maintenanceTabInstance = new MaintenanceTab();
            [B]maintenanceTabInstance.TradingSystemTabInstance = tradingSystemTabInstance;[/B]
            
            tabControl.AddNTTabPage([B]tradingSystemTabInstance[/B]);
            tabControl.AddNTTabPage([B]maintenanceTabInstance[/B]);
            }
            
            public class MaintenanceTab : NTTabPage
            {
            [B]public TradingSystemTab TradingSystemTabInstance;[/B]
            
            public MaintenanceTab()
            {
            }
            }
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              now i understand it.
              Big Thanks to you, especialy because in fact that was c# and not NinjaScript.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Kaledus, Today, 01:29 PM
              0 responses
              3 views
              0 likes
              Last Post Kaledus
              by Kaledus
               
              Started by PaulMohn, Today, 12:36 PM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by yertle, Yesterday, 08:38 AM
              8 responses
              36 views
              0 likes
              Last Post ryjoga
              by ryjoga
               
              Started by rdtdale, Today, 01:02 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              3 responses
              18 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X