• 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

New AddOn: Add tool tips to drawing objects

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

    New AddOn: Add tool tips to drawing objects

    Usage

    This add-on adds three methods to the drawing objects. The methods are SetToolTipText (string), SetToolTipContent (object), and SetToolTipContentFactory (Func<object>). You only need to call one of these methods in order to apply your tooltip. The one you use will depend on your scenario.

    Scenario One

    In the simple case, you can use the SetToolTipText method to display a simple string.

    Code:
    var drawing = Draw.Dot(...);
    drawing.SetToolTipText("Hello, world!");
    Or:

    Code:
    Draw.Dot(...).SetToolTipText("Hello, world!");
    Scenario Two

    To display controls on a few objects, you can use the SetToolTipContent method to provide your element tree.

    Code:
    var drawing = Draw.Dot(...);
    var button = new Button { Content = "Hello" };
    button.Click += (_, __) => button.Content = "World";
    drawing.SetToolTipContent(button);
    Most likely, you will be calling this from the OnBarUpdate method. If this is the case, there will be an exception thrown because this method is not necessarily being called from the UI thread. I've included a method on Indicator that helps with this (You can add a similar one to Strategy if needed). The resulting code to do the above would be:

    Code:
    var drawing = Draw.Dot(...);
    Dispatch(() =>
        {
            var button = new Button { Content = "Hello" };
            button.Click += (_, __) => button.Content = "World";
            drawing.SetToolTipContent(button);
        });
    Scenario Three

    To display controls on many objects, you can use the SetToolTipContentFactory method to provide your element tree. The method you provide will be called only when the tooltip is shown. After the tooltip is hidden, the object instance you returned from the factory will be eligible for garbage collection.

    If you are creating custom tooltips for many drawing objects, it is recommended that you use this method since it will use the least amount of memory. Keep in mind that the function you provide can be called zero or many times.

    Code:
    var drawing = Draw.Dot(...);
    drawing.SetToolTipContentFactory(() =>
        {
            var button = new Button { Content = "Hello" };
            button.Click += (_, __) => button.Content = "World";
            return button;
        });
    Installation:

    Place the attached file in the AddOns folder.

    NOTES:
    • A new menu item under the Tools menu allows enabling/disabling. It does not work properly, however, after compiling. Will look for a workaround
    • After compiling, the chart will need to be refreshed for existing tooltips to show. This is because the tooltips are not stored on the drawings themselves
    • Be aware of captures when using lambdas. Assign indicator properties to local variables and use the local variables in the lambdas.
    • There are several classes in the file. They can be put into their own files is desired
    • I'm using .Net 4.7 but I believe I've used only 4.5 features in this file. If it doesn't compile for you, let me know and I will fix it
    Attached Files

    #2
    I really like all the possibilities this can open, but my knowledge in C# is limited, i am self taught so I get lost in some basic stuff. Can anybody throw a simple indicator on how to use this addon. Not sure how to make it work. Thank in advance.

    I try this without success:

    Draw.Square(this,"MySquare" + CurrentBar, true, 0, High[0] + 2 * TickSize, Brushes.Red).SetToolTipText("My Text");

    It doesn't compile.

    Comment


      #3
      Hi PrTester,

      Post the compilation error and I'll have a look.

      I take it the AddOn compiled with no problems?

      Wil

      Comment


        #4
        BTW: Make sure you've added "using NinjaTrader.Custom.AddOns" to your indicator.

        Comment


          #5
          Everything is working now, it was a long night, nothing a computer and NT re-start with a new day cannot fix. I will continue play with, but work as describe and better. Thanks, great addition.

          Comment


            #6
            Good to hear. Hope everything works out for you.

            Comment


              #7
              Hey. Thanks for the add-on. It is possible to finish for objects SharpDX.Direct2D1. Thank you.

              Comment


                #8
                Hi Arkadiy_B,

                I do not understand what you are asking for.

                Comment


                  #9
                  Hey.
                  I tried to use your add-on in my indicator. I have an OnRender method. in which I put on chart graphic objects created with the help of
                  RenderTarget.FillEllipse(new SharpDX.Direct2D1.Ellipse(new SharpDX.Vector2(x, y), size, size), brushDX);
                  I would like to attach a tooltrip here

                  Comment


                    #10
                    Okay. I see.

                    This is a totally different animal. What you are doing is just rendering, there is no underlying object instance being created to which you can attach/monitor.

                    You have two options:
                    1. Change your design so you are creating actual objects (using Draw.XXX methods)
                    2. Create a collection to keep track of the objects you are rendering (or just their bounds and tool tip) and implement the tool tip functionality


                    The first method is easier.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by quantera, Today, 05:38 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post quantera  
                    Started by ciro1963, Today, 03:58 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post ciro1963  
                    Started by swcooke, Today, 02:48 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by SOFI777, Today, 01:03 PM
                    5 responses
                    29 views
                    0 likes
                    Last Post SOFI777
                    by SOFI777
                     
                    Started by Gerard111, 09-23-2015, 07:25 AM
                    2 responses
                    1,207 views
                    0 likes
                    Last Post NinjaTrader_ChristopherD  
                    Working...
                    X