Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendKeys Use with NT8

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

    SendKeys Use with NT8

    I have NT7 indicators where I used SendKeys.Send to use hot keys etc. When I try to use send keys in NT8 I need :using System.Windows.Forms;" but I am getting errors when I add that to the using declarations. Any workarounds for this?

    #2
    Hello,

    Thank you for the question.

    This would be expected as NinjaTrader 8 does no use Windows Forms but instead uses WPF.

    You can add the DLL reference to System.Windows.Forms if needed but there may be other ways to do what you are currently doing with sendkeys, can you provide more details on what this would be used for?

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

    Comment


      #3
      Thank you for your reply. I have used send keys to do anything I can assign a hot key to like
      1) open new chart
      2) draw line
      3) copy
      4) paste
      5) send right click events and send keys to open and load chart templates
      6) set colors to transparent or another color so items would show/hide


      They are all tied to button clicks on a custom toolbar I made. There probably are easier ways but with my more limited coding skills the sendkeys allowed me a simple method to do many things.

      This is the error I get when I add using System.Windows.Forms to my code:

      'Button' is an ambiguous reference between 'System.Windows.Controls.Button' and 'System.Windows.Forms.Button

      this is in reference to "private Button exampleButton;"

      Please let me know if more details are needed. Thanks again for your help.

      Comment


        #4
        Originally posted by jhowinvest View Post
        This is the error I get when I add using System.Windows.Forms to my code:

        'Button' is an ambiguous reference between 'System.Windows.Controls.Button' and 'System.Windows.Forms.Button

        this is in reference to "private Button exampleButton;"

        Controls and Forms both have buttons and because of both using statements, your code doesn't know which one you are refereeing too.. declare your button specifically with one or other..

        Code:
         private Systems.Windows.Controls.Button exampleButton = new System.Windows.Controls.Button();
        -=Edge=-
        NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

        Comment


          #5
          Here is an example code that places bar numbers below bars and has a toolbar button to toggle the numbers on or off. Credit for the bar numbers themselves goes elsewhere (not sure who but thank you to whoever made it for NT7). I am just working on quickly turning them from visible to invisible using a transparent brush. A few issues/questions:

          1) The showbutton bool is not set as checked by default so you have to turn it on while adding indicator. Can someone let me know how to make it checked by default?

          2) If the bar numbers color is changed to anything but dimgray then the button does not turn it off and on like I want. I know the code is set up to only work with dimgray and transparent so if anyone can help identify a better way that would allow it to be switched back and forth between transparent and any color then please let me know.

          3) I have my code working well to add images to buttons and change the text font of buttons in NT7 but the windows.controls.button format NT8 is using has me confused on how to do this. Here are two small snippets of what I was doing with NT7 for issue 3.

          //Set text of button
          button = new ToolStripButton("#s");
          button = new ToolStripButton("#s");
          button.Font = new Font("Arial", 8,FontStyle.Bold);

          //Set image for button
          btnDeletebutton = new System.Windows.Forms.ToolStripButton("btnDelete");
          btnDeletebutton.DisplayStyle = ToolStripItemDisplayStyle.Image;
          btnDeletebutton.Image = Image.FromFile(Cbi.Core.InstallDir + @"\ToolbarImages\deletebutton.jpg");
          btnDeletebutton.Alignment = ToolStripItemAlignment.Left;
          btnDeletebutton.ToolTipText = "Delete Single Drawing";



          I hope this helps with those that are trying to use toolbar buttons. I want as many shortcuts as possible to reduce clicks and keystrokes and this is a start.
          Attached Files

          Comment


            #6
            Originally posted by jhowinvest View Post
            Here are two small snippets of what I was doing with NT7 for issue 3.I hope this helps with those that are trying to use toolbar buttons. I want as many shortcuts as possible to reduce clicks and keystrokes and this is a start.
            All of the sample code you posted is for System.Windows.Forms.. With NT8 you will need to use System.Windows.Controls instead.. Take a look at this thread

            Buttons-StackPanels-DockPanels

            as there are examples there of both placing a button in NT8 toolbar and placing panels with buttons on the chart itself..


            -=Edge=-
            NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

            Comment


              #7
              Thanks Edge. I used your thread to help me get to this point with NT8 but I am not finding resources that show how to use System.Windows.Controls in any more detail.

              For example this link has all of the snippets missing. It show buttons but doesn't show any c# code for them:



              Still need help on issues 1-3 from my earlier posts. I think the code I attached can help get the ball rolling for adding buttons that help make doing basic chart related things more efficient but the buttons will be much better if we have the functionality of System.Windows.Forms

              I attached pictures of one of my NT7 charts with my main toolbar indicator and my mini dockable toolbar that both include copy and paste, delete, open new chart, load chart templates etc. I think this is useful and others might find it useful as well but NT8 doesn't seem to be as easy to work with for this. I just want to be able to quickly and efficiently do the things I need to do often during the trading day without right clicking, selecting, and/or making 2-4 clicks or hitting multiple hotkeys on the keyboard when the NT7 toolbars I made allow me to do it all with one click.
              Attached Files
              Last edited by jhowinvest; 09-25-2015, 09:56 PM.

              Comment


                #8
                I updated the code which resolved issue 1 from my earlier post #5. I also added buttons for line, ray, delete, copy, paste, increase/decrease bar spacing, increase decrease bar thickness and load chart template. The load chart template isn't working completely (Only the right click menu is accessed) NT7 allowed you to hit "t" for template then "l" for load on the keyboard to complete the load template. All of this is done with send keys. The buttons are ugly because I can only use text for them. Still hoping someone can help us shed light on how to improve the look of the buttons. Also, if anyone has any improvements or wants to build from this then please do and share. The goal of this is to give us one click access to frequently used items. Code is set up to allow any buttons to be left off by un-checking in the parameters.

                FYI...for some reason the default hotkeys for increase/decrease bar spacing would not take so I changed them to alt-0 and ctrl-0 so anyone who tries to use the buttons will have to do the same.
                Attached Files
                Last edited by jhowinvest; 09-26-2015, 06:26 AM.

                Comment


                  #9
                  To follow up. All code snippets I am finding for WPF and incorporating images for buttons are for xaml and not c#. Below is an example:

                  <Button>
                  <StackPanel>
                  <Image Source="Pictures/apple.jpg" />
                  <TextBlock>Disconnect from Server</TextBlock>
                  </StackPanel>
                  </Button>

                  Comment


                    #10
                    Originally posted by jhowinvest View Post
                    I updated the code which resolved issue 1 from my earlier post #5. I also added buttons for line, ray, delete, copy, paste, increase/decrease bar spacing, increase decrease bar thickness and load chart template. The load chart template isn't working completely (Only the right click menu is accessed) NT7 allowed you to hit "t" for template then "l" for load on the keyboard to complete the load template. All of this is done with send keys. The buttons are ugly because I can only use text for them. Still hoping someone can help us shed light on how to improve the look of the buttons. Also, if anyone has any improvements or wants to build from this then please do and share. The goal of this is to give us one click access to frequently used items. Code is set up to allow any buttons to be left off by un-checking in the parameters.

                    FYI...for some reason the default hotkeys for increase/decrease bar spacing would not take so I changed them to alt-0 and ctrl-0 so anyone who tries to use the buttons will have to do the same.
                    Looks like you've got a good start.. That's the problem with using sendkey to activate hot keys as your button click event, your limiting anyone from personally customizing their hotkeys.. You might want to combine all those Dispatcher calls in the terminate to just one call (like you've done in the config), and there is no need for all the !isToolBarButtonAdded checks in all those if's in the config.. (you've already checked that prior to running the dispatcher in the first place)..

                    Button images, get a bit tricky.. one way, since it looks like your using a physical image located on your computer, would be creating a BitmapImage using a Uri as souce, then using that as the source to an Image, then using that Image as the btn.content.. heh.. Search "WPF Dynamic Button Image" from yahoo and the very first result should get you started.. "Dynamic" being the key word to get around all the xaml examples..

                    But I definitely use buttons for everything! Wouldn't have an indicator without one! There are no splitbuttons in wpf... That's all done with context menu's now.. and although I do find this wpf way more cumbersome to code, it's all doable!



                    For things like my drawbar and color palette, rather than cluttering up the indicator properties window and the cumbersome way of changing all those settings, I'm going to use context menus along with my own property window that can all be accessed with a simple click of the indicators button icon..



                    Almost ready to release a few products, just need to finalize my personal server authentication check, finish up a few more code tweaks, and should be ready to go..


                    Attached Files
                    -=Edge=-
                    NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                    Comment


                      #11
                      Awesome. Thank you for your post Edge. I will check out those links. Your screenshots look great. Looks like you have made some great progress with the tool bars. Thanks again.

                      Comment


                        #12
                        Originally posted by jhowinvest View Post
                        Awesome. Thank you for your post Edge. I will check out those links. Your screenshots look great. Looks like you have made some great progress with the tool bars. Thanks again.
                        Thanks.. It's been a lot of long hard hours, with most of it probably being reading and research vs the coding itself.. Well maybe not most, but there is defiantly a learning curve involved here.. Still have a ton to do, but things are defiantly starting to look up, yes. Good luck to you as well..


                        -=Edge=-
                        NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                        Comment


                          #13
                          Here is what I have tried and the image is not showing up. It may be a simple syntax error but it continues to compile and has no errors but the image is not showing up. I have commented out several lines that I have tried. None have worked so far to get the image.

                          //btnLine = new System.Windows.Controls.Button { Content = "o-o" };
                          btnLine = new System.Windows.Controls.Button();

                          //BitmapImage btm = new BitmapImage(new Uri("c://ToolbarImages/Line1.jpg", UriKind.Relative));
                          //BitmapImage btm = new BitmapImage(new Uri("c://ToolbarImages\Line1.jpg", UriKind.Relative));
                          //BitmapImage btm = new BitmapImage(new Uri(startupPath+ @"\ToolbarImages\Line1.jpg", UriKind.Relative));
                          BitmapImage btm = new BitmapImage(new Uri("c://ToolbarImages/Line1.jpg", UriKind.Relative));

                          Image img = new Image();

                          img.Source = btm;

                          img.Stretch = Stretch.Fill;
                          btnLine.Content = img;
                          btnLine.Click += btnLine_Click;
                          chartWindow.MainMenu.Add(btnLine);

                          Comment


                            #14
                            Originally posted by jhowinvest View Post
                            Here is what I have tried and the image is not showing up. It may be a simple syntax error but it continues to compile and has no errors but the image is not showing up.
                            Simple Search of "WPF BitmapImage" .. Again first result..

                            BitmapImage Class


                            -=Edge=-
                            NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                            Comment


                              #15
                              I tried the converting bitmap code several ways with trial and error and could not get it to work.
                              I found this link: https://social.msdn.microsoft.com/Fo...ding?forum=wpf

                              I used that method and I can get the image for the button. This may not be an efficient way but it is working. Here is the code that is working in case it will help anyone else.


                              if (!isToolBarButtonAdded && showLine)

                              {
                              btnLine = new System.Windows.Controls.Button();
                              ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(NinjaTrader.Core.Globals.InstallDir+@"\Toolbar Images\line1.jpg")));
                              brush.Stretch = Stretch.Uniform;//uniform seems to work best
                              btnLine.Background = brush;
                              btnLine.Content = " ";//3spaces

                              btnLine.Click += btnLine_Click;
                              chartWindow.MainMenu.Add(btnLine);
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Gerik, Today, 09:40 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by RookieTrader, Today, 09:37 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by alifarahani, Today, 09:40 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post alifarahani  
                              Started by KennyK, 05-29-2017, 02:02 AM
                              3 responses
                              1,284 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              11 responses
                              186 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X