Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disabling keyDown event in Chart?

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

    Disabling keyDown event in Chart?

    Is there's a way to disable the "main" KeyDown eventhandler, when the Chart do not have the focus for example?
    It's when you type "10M" for example in chart to change the data interval of the bars.

    When I add another Grid in a Chart, with some TextBox, my keyDown events works but are also trapped by a kind of "master" eventHandler which makes things difficult to use...

    #2
    I received this by email but no reply in the thread iself, from NinjaTrader_Brandon:
    ***************
    Hello,

    Thanks for your post.

    I'm not following what it is that you are trying to do or what is not working. Please clarify.
    ***************

    I have a simple strategy which is adding a textbox in a Chart:


    It's possible to delete the text inside this TextBox, and do some copy/paste in it, see http://screencast.com/t/MF3sdbqVnUTy for example .

    But if I type something in it (KeyDown event), and "A" for example I have this: http://screencast.com/t/6bnXEE6v , which is the normal behaviour but I want to avoid it.
    I want my own keyDown eventhandler to manage what I'm entering in this box.

    I hope it's more clear like that.
    I presume it's not "supported", but if there is a solution...

    Thanks,
    Sam

    Comment


      #3
      Hi sam028,

      Thanks for your post.

      I am currently looking into this for you.
      I appreciate your patience while I work with development to find an answer.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi sam028,

        NinjaTrader_Matthew was able to create an example for you to demonstrate capturing key events.

        To do this, a text box was added to the panel, and then the TextBox_PreviewKeyDown is assigned to the text box keydown listener. Last the key press event is set to handled to prevent any further action after the TextBox_PreviewKeyDown runs.

        So anytime you type in the text box, this does not open the Data Series box.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks to you and to @NinjaTrader_Matthew !
          I did found a workaround but this solution is simpler.

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hi sam028,

            NinjaTrader_Matthew was able to create an example for you to demonstrate capturing key events.

            To do this, a text box was added to the panel, and then the TextBox_PreviewKeyDown is assigned to the text box keydown listener. Last the key press event is set to handled to prevent any further action after the TextBox_PreviewKeyDown runs.

            So anytime you type in the text box, this does not open the Data Series box.
            I may have missed something, I can't get this to compile.

            Is this part of another Indicator?
            Attached Files

            Comment


              #7
              Hi NJA_MC,

              Thanks for letting us know.

              In the current build of Beta 3 this is not accessible and the script will not compile. However, I am being told this will available again in the future. So in next beta release this should work.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                previewKeyDown Method for Textboxes within the chartGrid

                Hey guys I ran into the same issue and wrote this today for PreviewKeyDown for TextBoxes. It is missing a few buttons (mainly characters) that I didn't want users to use for databasing purposes but hope it helps a few out. It has all the functions of a typical keyboard stroke including, delete, backspace, shift for uppercase and other characters on keyboard.

                Code:
                private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
                				{
                					e.Handled = true;
                					
                					// handle the keydown event for the text box,					
                					TextBox textBoxSender = (TextBox)sender;
                					string textBoxText = textBoxSender.Text;
                					if (e.Key.ToString() == "Space")
                						textBoxText += " ";
                					
                					else if (e.Key.ToString() == "Back" && textBoxSender.Text.Length > 0)
                					{
                						if (textBoxSender.SelectedText != "")
                						{
                							int index1 = textBoxSender.SelectionStart;
                							textBoxSender.Text = textBoxSender.Text.Replace(textBoxSender.Text.Substring(textBoxSender.SelectionStart, textBoxSender.SelectionLength), "");
                							textBoxSender.SelectionStart = index1;
                							return;
                						}
                												
                						int index = textBoxSender.SelectionStart;
                						if (index == 0)
                							return;
                						if (index <= textBoxSender.Text.Length)
                						{
                							int lengthOfString = textBoxSender.Text.Length;
                							string firstHalf = textBoxSender.Text.Substring(0, index - 1);
                							string secondHalf = textBoxSender.Text.Substring(index, lengthOfString- index);
                							textBoxText = firstHalf + secondHalf;
                							textBoxSender.Text = textBoxText;
                							textBoxSender.SelectionStart = index - 1;
                						}
                						else
                						{
                							
                						}
                						return;
                					}
                					else if (e.Key.ToString() == "Back")
                						return;
                					else if (e.Key.ToString() == "Delete" && textBoxSender.Text.Length > 0)
                					{
                						if (textBoxSender.SelectedText != "")
                						{
                							int index1 = textBoxSender.SelectionStart;
                							textBoxSender.Text = textBoxSender.Text.Replace(textBoxSender.Text.Substring(textBoxSender.SelectionStart, textBoxSender.SelectionLength), "");
                							textBoxSender.SelectionStart = index1;
                							return;
                						}						
                						
                						int index = textBoxSender.SelectionStart;
                						
                						if(index < textBoxSender.Text.Length)
                						{
                							string firstHalf = textBoxSender.Text.Substring(0, index);
                							string secondHalf = textBoxSender.Text.Substring(firstHalf.Length+1);
                							textBoxText = firstHalf + secondHalf;
                							textBoxSender.Text = textBoxText;
                							textBoxSender.SelectionStart = index;
                						}
                						return;
                					}
                					else if (e.Key.ToString() == "Delete")
                						return;
                					else if (e.Key.ToString() == "Capital")
                						return;
                					else if (e.Key.ToString() == "Left")
                					{
                						if (textBoxSender.SelectionStart > 0)
                							textBoxSender.SelectionStart = textBoxSender.SelectionStart - 1;
                						return;
                					}
                					else if (e.Key.ToString() == "Right")
                					{
                						if (textBoxSender.SelectionStart < textBoxSender.Text.Length)
                							textBoxSender.SelectionStart = textBoxSender.SelectionStart + 1;
                						return;
                					}
                					else
                					{
                						
                						int index = 0;
                						if (textBoxSender.Text.Length > 0)
                							index = textBoxSender.SelectionStart;
                						string firstHalf = "";
                						string secondHalf = "";
                						if(index < textBoxSender.Text.Length)
                						{
                							firstHalf = textBoxSender.Text.Substring(0, index);
                							secondHalf = textBoxSender.Text.Substring(firstHalf.Length);
                							
                						}
                						else if (index == 0)
                						{
                							
                						}
                						else
                						{
                							firstHalf = textBoxSender.Text.Substring(0, index);
                						}
                						string toAdd = "";
                						
                						if 
                						(
                							(Keyboard.IsKeyToggled(Key.CapsLock) || (Keyboard.IsKeyDown(Key.LeftShift) || 
                							Keyboard.IsKeyDown(Key.RightShift))) && e.Key.ToString().Length == 1
                						)
                						{
                							toAdd = e.Key.ToString();
                						}
                						else if (e.Key.ToString().Length == 1)
                							toAdd = e.Key.ToString().ToLower();
                						else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                						{
                							if (e.Key == Key.D0)
                								toAdd = ")";
                							if (e.Key == Key.D1)
                								toAdd = "!";
                							if (e.Key == Key.D2)
                								toAdd = "@";
                							if (e.Key == Key.D3)
                								toAdd = "#";
                							if (e.Key == Key.D4)
                								toAdd = "$";
                							if (e.Key == Key.D5)
                								toAdd = "%";
                							if (e.Key == Key.D6)
                								toAdd = "^";
                							if (e.Key == Key.D7)
                								toAdd = "&";
                							if (e.Key == Key.D8)
                								toAdd = "*";
                							if (e.Key == Key.D9)
                								toAdd = "(";	
                							if (e.Key == Key.OemSemicolon)
                								toAdd = ":";						
                							
                						}
                						else 
                						{
                							if (e.Key == Key.D0)
                								toAdd = "0";
                							if (e.Key == Key.D1)
                								toAdd = "1";
                							if (e.Key == Key.D2)
                								toAdd = "2";
                							if (e.Key == Key.D3)
                								toAdd = "3";
                							if (e.Key == Key.D4)
                								toAdd = "4";
                							if (e.Key == Key.D5)
                								toAdd = "5";
                							if (e.Key == Key.D6)
                								toAdd = "6";
                							if (e.Key == Key.D7)
                								toAdd = "7";
                							if (e.Key == Key.D8)
                								toAdd = "8";
                							if (e.Key == Key.D9)
                								toAdd = "9";
                							
                							if (e.Key == Key.NumPad0)
                								toAdd = "0";
                							if (e.Key == Key.NumPad1)
                								toAdd = "1";
                							if (e.Key == Key.NumPad2)
                								toAdd = "2";
                							if (e.Key == Key.NumPad3)
                								toAdd = "3";
                							if (e.Key == Key.NumPad4)
                								toAdd = "4";
                							if (e.Key == Key.NumPad5)
                								toAdd = "5";
                							if (e.Key == Key.NumPad6)
                								toAdd = "6";
                							if (e.Key == Key.NumPad7)
                								toAdd = "7";
                							if (e.Key == Key.NumPad8)
                								toAdd = "8";
                							if (e.Key == Key.NumPad9)
                								toAdd = "9";
                							
                							if (e.Key == Key.Divide)
                								toAdd = "/";
                							if (e.Key == Key.Multiply)
                								toAdd = "*";
                							if (e.Key == Key.Subtract)
                								toAdd = "-";
                							if (e.Key == Key.Add)
                								toAdd = "+";
                							if (e.Key == Key.Decimal || e.Key == Key.OemPeriod)
                								toAdd = ".";
                							
                							
                							if (e.Key == Key.OemMinus)
                								toAdd = "-";						
                							if (e.Key == Key.OemPlus)
                								toAdd = "+";						
                							if (e.Key == Key.OemOpenBrackets)
                								toAdd = "[";					
                							if (e.Key == Key.OemCloseBrackets)
                								toAdd = "]";	
                							if (e.Key == Key.OemSemicolon)
                								toAdd = ";";
                						
                						}
                						if (textBoxSender.SelectionLength == 0)
                						{
                							textBoxText = firstHalf + toAdd + secondHalf;
                							textBoxSender.Text = textBoxText;
                						}
                						else
                							textBoxSender.Text = textBoxSender.Text.Replace(textBoxSender.Text.Substring(textBoxSender.SelectionStart, textBoxSender.SelectionLength), toAdd);
                						
                						
                						if (toAdd != "")
                							textBoxSender.SelectionStart = index + 1;
                						else
                							textBoxSender.SelectionStart = index;
                							
                					}
                				}

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ghoul, Today, 06:02 PM
                2 responses
                12 views
                0 likes
                Last Post ghoul
                by ghoul
                 
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                44 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                20 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                180 views
                0 likes
                Last Post jeronymite  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Working...
                X