Announcement

Collapse
No announcement yet.

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:	339
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.




    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:	314
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.

        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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X