Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

drawing text with spaces to the right

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

    drawing text with spaces to the right

    Hello,

    I want to draw a text that I enclose on both sides with <space> characters to enlarge the box around the text. But this only works on the left side of the text, not on the right:

    The output for both strings is identical (text box ends after the character "5"):
    a) " 12345"
    b) " 12345 "

    How can I extend the text box? Do I need to add other characters than " " as they appear to get cut off on the right side of the string.

    Thanks,
    NutFlush

    #2
    NutFlush, I would not expect any effect of adding spaces with those draw statements, but rather feel you see the effects perhaps due to different string alignments used? Which call do you exactly use here?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NutFlush View Post
      Hello,

      I want to draw a text that I enclose on both sides with <space> characters to enlarge the box around the text. But this only works on the left side of the text, not on the right:

      The output for both strings is identical (text box ends after the character "5"):
      a) " 12345"
      b) " 12345 "

      How can I extend the text box? Do I need to add other characters than " " as they appear to get cut off on the right side of the string.

      Thanks,
      NutFlush
      Format your string using String.Format, and include the spaces.

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        NutFlush, I would not expect any effect of adding spaces with those draw statements, but rather feel you see the effects perhaps due to different string alignments used? Which call do you exactly use here?
        I am using DrawTextFixed() which doesn't have any alignment settings. The text box only includes the space in the beginning of the string. The spaces at the end are cut off. The only way I found so far to expand the box is to include yet another character like "." after all the spaces. But then I see the "." which is also not what I want.

        Is there some other character or control code that I can use to extend the string by an "invisible" character?

        Thanks,
        NutFlush

        Comment


          #5
          Originally posted by koganam View Post
          Format your string using String.Format, and include the spaces.
          How would I do that if I have a text like "strategy engaged" that I want to turn into " strategy engaged " (no numbers)?

          Thanks,
          NutFlush

          Comment


            #6
            Originally posted by NutFlush View Post
            How would I do that if I have a text like "strategy engaged" that I want to turn into " strategy engaged " (no numbers)?

            Thanks,
            NutFlush
            A little Google-Fu: https://www.google.com/search?q=stri...Bc%23+%2Btable

            Comment


              #7
              Originally posted by koganam View Post
              I appreciate your effort Google-san!

              Unfortunately this table-formatting doesn't help. The spaces to the right are still cut off.

              None of this works:
              String.Format("{0,10}", "hello ")
              String.Format("{0,-10}", "hello ")
              String.Format("{0,10}", "hello")
              String.Format("{0,-10}", "hello")

              Or did you mean another kind of format? Did you get it to work?

              Cheers,
              NutFlush

              Comment


                #8
                Originally posted by NutFlush View Post
                I appreciate your effort Google-san!

                Unfortunately this table-formatting doesn't help. The spaces to the right are still cut off.

                None of this works:
                String.Format("{0,10}", "hello ")
                String.Format("{0,-10}", "hello ")
                String.Format("{0,10}", "hello")
                String.Format("{0,-10}", "hello")

                Or did you mean another kind of format? Did you get it to work?

                Cheers,
                NutFlush
                As this over-elaborate example shows (by using a colored background to act as a visual clue to position), you can pretty much visually position anything within the reserved space for your text.
                Code:
                			DrawTextFixed("Example", 
                								     String.Format("{0,-10}", "hello")
                							+ "\n" + String.Format("{0,-10}", " hello")
                							+ "\n" + String.Format("{0,-10}", "  hello")
                							+ "\n" + String.Format("{0,-10}", "   hello")
                							+ "\n" + String.Format("{0,10}", "hello")
                							+ "\n" + String.Format("{0,10}", "hello ")
                							+ "\n" + String.Format("{0,10}", "hello  ")
                							+ "\n" + String.Format("{0,10}", "hello   "),
                							TextPosition.BottomRight,Color.Blue,new Font(FontFamily.GenericMonospace,10f,FontStyle.Bold),Color.Empty,Color.Gray,2);

                Comment


                  #9
                  Originally posted by koganam View Post
                  As this over-elaborate example shows (by using a colored background to act as a visual clue to position), you can pretty much visually position anything within the reserved space for your text.
                  Code:
                              DrawTextFixed("Example", 
                                                       String.Format("{0,-10}", "hello")
                                              + "\n" + String.Format("{0,-10}", " hello")
                                              + "\n" + String.Format("{0,-10}", "  hello")
                                              + "\n" + String.Format("{0,-10}", "   hello")
                                              + "\n" + String.Format("{0,10}", "hello")
                                              + "\n" + String.Format("{0,10}", "hello ")
                                              + "\n" + String.Format("{0,10}", "hello  ")
                                              + "\n" + String.Format("{0,10}", "hello   "),
                                              TextPosition.BottomRight,Color.Blue,new Font(FontFamily.GenericMonospace,10f,FontStyle.Bold),Color.Empty,Color.Gray,2);
                  Thanks a lot, again! Unfortunately the spaces to the right are only there because the 4th text piece moves the border of the text box over to the right. If I use any of those text pieces "hello" without all the others then there are no spaces to the right anymore. Like in this:
                  Code:
                              DrawTextFixed("Example", 
                                                       String.Format("{0,10}", "hello   "),
                                              TextPosition.BottomRight,Color.Blue,new  Font(FontFamily.GenericMonospace,10f,FontStyle.Bold),Color.Empty,Color.Gray,2);
                  Do you get a different result with spaces to the right of "hello"?

                  Sorry, to bother you again - and thanks!!!

                  NutFlush

                  Comment


                    #10
                    Originally posted by NutFlush View Post
                    Thanks a lot, again! Unfortunately the spaces to the right are only there because the 4th text piece moves the border of the text box over to the right. If I use any of those text pieces "hello" without all the others then there are no spaces to the right anymore. Like in this:
                    Code:
                                DrawTextFixed("Example", 
                                                         String.Format("{0,10}", "hello   "),
                                                TextPosition.BottomRight,Color.Blue,new  Font(FontFamily.GenericMonospace,10f,FontStyle.Bold),Color.Empty,Color.Gray,2);
                    Do you get a different result with spaces to the right of "hello"?

                    Sorry, to bother you again - and thanks!!!

                    NutFlush
                    On further reflection, it appears that Microsoft pads/substitutes with white space for spaces unless there is non-space trailing letter, so you must pad with another character/letter, other than a space.

                    Comment


                      #11
                      Originally posted by koganam View Post
                      On further reflection, it appears that Microsoft pads/substitutes with white space for spaces unless there is non-space trailing letter, so you must pad with another character/letter, other than a space.
                      Thanks for your effort!

                      If this is a limitation imposed by M$ then I'll accept that - as unfortunate as it may be.

                      I found a little "workaround": I put \t at the end of the string to add a tab. This actually adds empty space to the text box, but of course you cannot control how much.

                      Cheers,
                      NutFlush

                      Comment


                        #12
                        Originally posted by NutFlush View Post
                        Thanks for your effort!

                        If this is a limitation imposed by M$ then I'll accept that - as unfortunate as it may be.

                        I found a little "workaround": I put \t at the end of the string to add a tab. This actually adds empty space to the text box, but of course you cannot control how much.

                        Cheers,
                        NutFlush
                        Shame on me. I actually thought about that, then went to sleep instead of posting. However, that sent me off on a tangent that showed me how to do exactly what you wanted in the first place.
                        "hello \b"
                        as the string will print all the intervening spaces!

                        Comment


                          #13
                          Originally posted by koganam View Post
                          Shame on me. I actually thought about that, then went to sleep instead of posting. However, that sent me off on a tangent that showed me how to do exactly what you wanted in the first place.

                          as the string will print all the intervening spaces!
                          HA!!! PERFECT!!!

                          You are my hero! Works like a charm!

                          Thanks a lot,
                          NutFlush

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by itrader46, Today, 09:04 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post itrader46  
                          Started by timmbbo, Today, 08:59 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post timmbbo
                          by timmbbo
                           
                          Started by bmartz, 03-12-2024, 06:12 AM
                          5 responses
                          33 views
                          0 likes
                          Last Post NinjaTrader_Zachary  
                          Started by Aviram Y, Today, 05:29 AM
                          4 responses
                          14 views
                          0 likes
                          Last Post Aviram Y  
                          Started by algospoke, 04-17-2024, 06:40 PM
                          3 responses
                          28 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X