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:	161
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?

    #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:	145
Size:	14.4 KB
ID:	1181810

      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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by crystalet, Yesterday, 12:19 PM
          3 responses
          34 views
          0 likes
          Last Post crystalet  
          Started by Orogpd, Today, 03:26 AM
          0 responses
          1 view
          0 likes
          Last Post Orogpd
          by Orogpd
           
          Started by cbdgrenhouseusa, Today, 03:17 AM
          0 responses
          1 view
          0 likes
          Last Post cbdgrenhouseusa  
          Started by cbdgrenhouseusa, Today, 03:16 AM
          0 responses
          1 view
          0 likes
          Last Post cbdgrenhouseusa  
          Started by ラリー, 09-05-2022, 02:02 PM
          62 responses
          513 views
          0 likes
          Last Post ラリー  
          Working...
          X