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

Keyboard.AddPreviewKeyDownHandler()

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

    Keyboard.AddPreviewKeyDownHandler()

    Hi, I have a string property.

    Click image for larger version

Name:	Screenshot_3.jpg
Views:	284
Size:	5.4 KB
ID:	1181751

    If the value is set (the field has lost focus), I would like to call an EventHandler so that I can determine in it which key is currently being pressed.
    Code:
    [Display(ResourceType = typeof(Resource), Order = 1, GroupName = "HotKeys", Name = "Pressed Key", Description = "")]
    public string TextField
    {[INDENT]get{ return textField; }[/INDENT][INDENT]set
    {[/INDENT][INDENT=2]textField = value;
    
    ??? Keyboard.AddPreviewKeyDownHandler(???, PreviewKeyDownHandler); ???[/INDENT][INDENT]}[/INDENT]
     }
    The Event method already has, but does not know exactly how, the handler is activated in the property and unloaded after use.
    Code:
    private void PreviewKeyDownHandler(object s, KeyEventArgs e)
    {[INDENT]
    TextField  = SidiExtensions.GetVirtualKeyCode(e.Key);[/INDENT]
     }
    For example, if I enter 2, the method (SidiExtensions.GetVirtualKeyCode(e.Key)) returns the number 36 (D2 = 36), these 36 should then be in the text field instead of the 2.

    Can someone help me with the eventhandler, how I have to integrate it exactly in the "TextField" property?
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    Unfortunately I wouldn't be able to provide any insight on adding handlers to the property dialog window. I am not aware of a way you could detect the key press in that area.

    You could use the Set from your property to call a method or check what the value was for validation.

    The other alternative here would be to create your own controls on the chart or in a custom window, you could then attach key event handlers to those controls directly. With public properties you would generally do any type of formatting or validation in the set method without any keyboard events, if the value is not correct for what it should be you would just not use value and specify the string for the backing variable textField instead.




    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi _Jesse, thank you for your reply. I now have a separate window that opens as soon as the focus detaches from the TextBox in the properties window of the indicator. How do I get the focus on this newly opened window, which I can make an input in it without closing the properties window of the indicator?

      Click image for larger version

Name:	Screenshot_4.jpg
Views:	250
Size:	14.4 KB
ID:	1181810
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment


        #4
        Hello sidlercom80,

        The focus would be to the dialog in that situation, its a dialog window so you cant click beyond it. You would need to make that a options window that you can open once the indicator has already been applied to make that type of window.

        For the property dialog the best case would be to use the set method to do any validation or changes needed to the string as the user types. That would not require using any key events and just using the property like a normal C# property with get/set.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks _Jesse, I got it ;-) doesn't inherit the class from NTWindow, but from Window, that's it.
          sidlercom80
          NinjaTrader Ecosystem Vendor - Sidi Trading

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Irukandji, Today, 09:34 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by RubenCazorla, Today, 09:07 AM
          1 response
          5 views
          0 likes
          Last Post RubenCazorla  
          Started by TraderBCL, Today, 04:38 AM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          11 responses
          1,423 views
          0 likes
          Last Post jculp
          by jculp
           
          Started by BarzTrading, Today, 07:25 AM
          2 responses
          29 views
          1 like
          Last Post BarzTrading  
          Working...
          X