• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Drawing for an AddOn...

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

    Custom Drawing for an AddOn...

    Hi there, have looked through threads didn't see anything quite like my question so...

    I have created AddOn which outputs and updates Text to a TextBox control. Works great.

    The TextBox however is limited to solid Fore/Back colors and would like to write my own control which lets me color the Text, as well as other drawing primitives like Rectangles and such around blocks of text. Basically an owner drawn control but hosted in the AddOn.

    In the C++ world have done this using a Button which is OwnerDrawn then do anything want rendering it in the OnPaint() method.

    Has NinjaTrader created any code samples which show owner drawn controls in an AddOn? They could be charts or even just a line of text.

    I'm new to NT and .Net programming still old school from MFC days in Windows. But learning...

    Thanks for any guidance!

    #2
    Hello,

    Thank you for the post.

    In this case, this wouldn't necessarily be something we would provide a sample of as this is a C#/Xaml concept.

    In the case just colors were needed, you could set the existing Background/Foreground properties for the TextBox. For custom drawing or otherwise a custom Control, you would need to create a UserControl in C# or C#+Xaml and then use that control instead.

    This isn't something that is easily explained in a forum post and is well documented in other locations. It sounds like you have some experience in creating controls in C++, it is a really similar process although the processes are different as Windows Forms is no longer used and WPF is now used. In general, you can accomplish the same goals of overriding the properties of a control to do custom things.

    Because of the nature of how NinjaTrader compiles, you would need to create a new UserControl in either all C# with no xaml, or create a new project in visual studio and compile the new control into an assembly which could be referenced in NinjaScript. NinjaTrader will not specifically compile the xaml so either all code would be needed or an assembly with your control compiled would need to be used.

    I located the following resource using google which may be helpful in learning how to create a custom control in WPF:

    https://www.codeproject.com/Articles...sing-it-in-a-W
    https://www.tutorialspoint.com/wpf/w...m_controls.htm

    For extending existing controls which may be what you want to do:
    https://wpftutorial.net/CustomVsUserControl.html
    https://stackoverflow.com/questions/...rty-to-textbox
    https://stackoverflow.com/questions/...x-with-caption

    Please also keep in mind that making custom controls will likely break the skin for that control meaning it would likely look strange or just like a default WPF control. In that situation, you may need to additionally apply custom styles or internal styles to the object to make it look similar to the existing platform controls.


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

    Comment


      #3
      Great thanks for the reply and links to articles Jesse! I have been hunting around but these are excellent direction. I might be able to simply subclass from the TextBox and extend the painting dynamics. Otherwise full custom control will work.

      Interestingly this is all going back to Terminal Emulation days what am needing to do.... These got really involved prior to bitmap graphics taking off... Wonder if anyone out there still remembers how that worked! Has been over twenty years now..

      Comment


        #4
        Hi again Jesse!

        Well I stumbled around for a bit but now have my own user drawn control which created and am rendering correctly external to NT. Have now tried to add this into NT itself as a control but not quite sure what need to do to bring it into the Borg Collective. Have tried adding "using" statement and put the correct entry in the xaml but think NT needs to know more where to find this new content.

        Are there some config files need to tweak with NT that will let me do this???

        Thanks again!

        Comment


          #5
          Hello,

          Thank you for the reply.

          I take it that you have created this control in an external C# project currently, is that correct? If so, are you compiling a DLL and need to reference that DLL or are you copying/pasting code from that project into a NinjaScript file?

          If you have an external project that creates a DLL, you would need to reference that DLL to be able to use "using" statements. In the case you had not referenced the DLL yet, this is likely why you can't use the "using" statements.
          To add a reference, add the DLL to the \Documents\NinjaTrader 8\bin\Custom directory and then in the NinjaScript editor, right click and choose References and then add a reference to the file copied to the \Documents\NinjaTrader 8\bin\Custom folder.

          After doing this, complete a compile for the editor to pick up the new code.


          I look forward to being of further assistance.

          If you are working on an external project, I would highly suggest looking at the addon project we provide in the help guide, this demonstrates a "suggested" way to create DLLs for NinjaScript that may contain an Addon or in your case a Control.
          http://ninjatrader.com/support/helpG...t_overview.htm
          The section that lists" Below is a complete Visual Studio project with this setup in place".

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

          Comment


            #6
            Thanks again for the helping hand! Yes this is as a DLL and once it was put into the right directory and reference added all the compilation and link occurred correctly - easy!

            The issue now is something with the XAML and/or my logic picking up the control at runtime. Am getting a null pointer return. What have done is replaced a TextBox named "outputBox" with a JCBUserControl:UserControl1 but it does not hook up correctly....

            Not that I want you to fully debug my code, but as this is new stuff to me perhaps a seasoned eye can save me a day trying to track this down with web searches??

            the Hookup code for the old and the new is:

            // Find Output Box - old way gets me the TextBox
            outputBox = LogicalTreeHelper.FindLogicalNode(pageContent, "outputBox") as TextBox;

            // Find my UserControl1 it returns NULL
            JCBOutput = LogicalTreeHelper.FindLogicalNode(pageContent, "JCBControl") as JCBUserControl.UserControl1;

            while the XAML which is not working is this (note red):

            <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:t="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrad er.Gui"
            xmlns:system="clr-namespace:System;assembly=mscorlib"
            xmlns:AccountPerformance="clr-namespace:NinjaTrader.Gui.AccountPerformance;assem bly=NinjaTrader.Gui"
            xmlns:AccountData="clr-namespace:NinjaTrader.Gui.AccountData;assembly=Nin jaTrader.Gui"
            xmlns:AtmStrategy="clr-namespace:NinjaTrader.Gui.NinjaScript.AtmStrategy; assembly=NinjaTrader.Gui" >
            xmlns:JCBUserControl="clr-namespace:JCBUserControl;assembly=JCBUserControl"
            <Grid Background="Transparent">
            <JCBUserControl:UserControl1 x:Name="JCBControl" Grid.Column="1" />
            </Grid>
            </Page>

            and what worked with the simple TextBox is this:

            <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:t="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrad er.Gui"
            xmlns:system="clr-namespace:System;assembly=mscorlib"
            xmlns:AccountPerformance="clr-namespace:NinjaTrader.Gui.AccountPerformance;assem bly=NinjaTrader.Gui"
            xmlns:AccountData="clr-namespace:NinjaTrader.Gui.AccountData;assembly=Nin jaTrader.Gui"
            xmlns:AtmStrategy="clr-namespace:NinjaTrader.Gui.NinjaScript.AtmStrategy; assembly=NinjaTrader.Gui" >
            <Grid Background="Transparent">
            <TextBox x:Name="outputBox" Margin="{Binding Source={StaticResource MarginBase}}" Grid.Column="1" IsReadOnly="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Disabled"
            FontFamily="Courier New" FontSize="11" FontStyle="Normal" FontWeight="Normal" Background="Black"/>

            </Grid>
            </Page>

            Thanks for any further help Jesse you have been very helpful so far! I'll figure out this .NET stuff yet.... (programming windows since '92 but stopped at MFC...)

            Comment


              #7
              Hello,

              Thank you for the reply.

              That looks like the correct snytax, out of context it would be difficult to say.

              Rather than debugging what you have tried, I have created a sample of a custom user control that inherits from TextBox.

              This is a little outside of what we would normally provide for a sample but because of the odd loading we use for the addon I feel this is the easier solution.

              I have included all the necessary parts, the visual studio solution to build the assembly with the control, and an Addon that uses the control.

              I added a custom dependency property to the control to demonstrate the Render override in the control also which is set in the xaml.

              The same steps would apply, you would first need to build the DLL in visual studio and copy it to the bin/custom folder and reference it.

              After doing this, you should be able to import the other zip with the addon

              Finally, you would need to extract the xaml file into the bin/custom/addons folder as well.



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

              Comment


                #8
                hey thanks very much Jesse! that is above and beyond the call of duty IMHO! your company has been very helpful indeed.

                i will check it out after market closes today should be quite helpful. thx again!

                -Jim

                [Update: your sample worked great. something weird was going on with my xaml that still can't explain but starting from yours was eventually able to get it to parse mine. it appears the parser was getting confused somehow. so actually when got past that my UserControl became active and worked like it did in my stub test program without any changes. whatever the xaml logic was doing seems pretty fuzzy with bizarre behavior. so things are running now can now augment my user control! thanks again!]
                Last edited by JimB17; 05-24-2017, 12:18 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Irukandji, Today, 09:43 AM
                0 responses
                1 view
                0 likes
                Last Post Irukandji  
                Started by TazoTodua, Today, 09:06 AM
                0 responses
                2 views
                0 likes
                Last Post TazoTodua  
                Started by sambo81, Yesterday, 06:57 PM
                1 response
                19 views
                0 likes
                Last Post NinjaTrader_ThomasC  
                Started by tgn55, Today, 08:34 AM
                0 responses
                4 views
                0 likes
                Last Post tgn55
                by tgn55
                 
                Started by TazoTodua, Today, 06:00 AM
                0 responses
                9 views
                0 likes
                Last Post TazoTodua  
                Working...
                X