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

Disabling Instrument selector on Chart

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

    Disabling Instrument selector on Chart

    I'm trying to be able to use a text box I've added to the chart control using

    Code:
    ChartWindow.MainMenu.Add([I]control[/I])
    The controls go on just fine, but when I try to change a value in them the instrument selector pops up.

    I've tried to use the example in this thread: http://ninjatrader.com/support/forum...PreviewKeyDown

    Unfortunately it's not working. When I implement the PreviewKeyDown event I get a CS0118 error.

    The bind event and event code are:

    TxtBxPositionSize.PreviewKeyDown += new TxtBxPositionSize_PreviewKeyDown(TxtBxPositionSize _PreviewKeyDown);


    private void TxtBxPositionSize_PreviewKeyDown(object sender, KeyEventArgs e)
    {
    // this is pretty dumb, but should get you started
    // might want to validate this by using SHIFT or something
    // so Overlay Instrument Selector isn't unusable...
    TextBox textBoxSender = (TextBox)sender;
    textBoxSender.Text += e.Key.ToString();
    // handle the keydown event for the text box

    e.Handled = true;

    Print("input keys: " + textBoxSender.Text);
    }
    This is pretty much copied exactly from the example given in the thread mentioned above so I'm baffled as to why I'm getting this error.

    Any help is much appreciated.

    Thanks
    daqu40
    NinjaTrader Ecosystem Vendor - QTradez

    #2
    Hello daqu40,

    The one thing I can see from your post is how you are creating the subscription to the event handler. Could you modify the following line to match the sample in the post you linked? Try just specifying the method like the following:

    Code:
    TxtBxPositionSize.PreviewKeyDown += TxtBxPositionSize _PreviewKeyDown;
    If you could provide a sample I can compile I could likely see what the error is more clearly.

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

    Comment


      #3
      That worked Jesse.

      So why does

      Code:
      TxtBxPositionSize.PreviewKeyDown += TxtBxPositionSize _PreviewKeyDown;
      work when all of my other event bindings use a format like

      Code:
      TxtBxTargetTicks.TextChanged += new TextChangedEventHandler(TxtBxTargetTicks_TextChanged);
      Thanks!
      daqu40
      NinjaTrader Ecosystem Vendor - QTradez

      Comment


        #4
        Hello,

        I beleive there is some confusion between what existing handlers you have and what you were trying.

        With the syntax you were trying it looks like you just copied the handlers method name twice:

        Code:
        TxtBxPositionSize.PreviewKeyDown += new [B]TxtBxPositionSize_PreviewKeyDown[/B]([B]TxtBxPositionSize_PreviewKeyDown[/B]);
        Where as the other handlers you created you defined a new type of handler (green) and provided the method as its target rather than just two of the same method name:

        Code:
        TxtBxTargetTicks.TextChanged += new [COLOR="SeaGreen"]TextChangedEventHandler[/COLOR]([B]TxtBxTargetTicks_TextChanged[/B]);
        By not specifying the type and creating a new instance of the handler, you can otherwise use the shorthand and just specify the target method like I had shown previously.

        Code:
        TxtBxPositionSize.PreviewKeyDown += TxtBxPositionSize _PreviewKeyDown;
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse,

          It was the use of the keyword new that was throwing me off. Got it all working now.
          daqu40
          NinjaTrader Ecosystem Vendor - QTradez

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X