• 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

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);
        http://ninjatrader.com/support/helpG...g_concepts.htm

        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();
            maintenanceTabInstance.TradingSystemTabInstance = tradingSystemTabInstance;
            
            tabControl.AddNTTabPage(tradingSystemTabInstance);
            tabControl.AddNTTabPage(maintenanceTabInstance);
            }
            
            public class MaintenanceTab : NTTabPage
            {
            public TradingSystemTab TradingSystemTabInstance;
            
            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 wolfcuring, Today, 01:29 AM
              0 responses
              1 view
              0 likes
              Last Post wolfcuring  
              Started by BrandonT1292, 06-17-2019, 03:03 PM
              2 responses
              22 views
              0 likes
              Last Post thinarthrill  
              Started by cbentrikin, Yesterday, 07:46 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by dr0832, 01-04-2019, 10:34 AM
              7 responses
              143 views
              0 likes
              Last Post Lancer
              by Lancer
               
              Started by RedDuke, Yesterday, 06:14 PM
              0 responses
              5 views
              0 likes
              Last Post RedDuke
              by RedDuke
               
              Working...
              X