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

length and measure

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

    #16
    Hi Mindset,

    you could try something like this:

    Code:
    SizeF mySizeF = graphics.MeasureString(incomingpath ,textFontBold);
    Size mySize = Size.Ceiling(mySizeF);
    Point myPoint = new Point(ChartControl.Bounds.Left, ChartControl.Bounds.Top);
    Rectangle rectangle1 = new Rectangle(myPoint,mySize);
    graphics.DrawRectangle(borderPen,rectangle1);
    Let me know how that works
    Ralph

    Comment


      #17
      Didn't know you could do that

      Interesting that Point can take x and y cords together.

      However like you I would prefer to work with integers so how do I convert

      my take is that I declare 2 points for the X and Y co ords.
      Then a height which I shall take off the text.height - but it all comes back to the width which is a SizeF or a Size but not an integer?

      I feel a lightbulb moment coming but right now I am in the darkest hole
      I feel quite annoyed asking these questions really - most things I have been able to work out but this has just got me.

      Comment


        #18
        Hi Mindset,

        You can derive the width and heigth integers from the Size struct.
        int height = mySize.Height
        int width = mysize.Width

        Regarding to your rectangle you need to make a decision between a Point() and a Size() or 2 coordinate-points. What you always have is a Size(). Then you either construct a Point() as in my example or you calculate the second coordinate-point like pointx+width and pointy+height.

        Regards
        Ralph

        Comment


          #19
          Eureka

          Many thanks for your patience Ralph.

          I believe I have got the rudiments of it now.
          Width and height are properties of the Size - Doh! a real Homer moment.

          Comment


            #20
            I could have pointed out that earlier, but sometimes it is not easy for me to recognise through the internet what exactly is the core of the issue at the other end of the cable.

            Btw, the other way around is also a good looking solution. You could instantiate a Point struct for your class and then you load it with the x nad y coordinate and finaly use the Rectangle(Point, Size):

            Point myPoint = new Point();
            ...
            myPoint.X = pointx
            myPoint.Y = pointy
            Rectangle rectangle1 = new Rectangle(myPoint, mySize)

            You are now spoilt for choice, is this expression correct?

            Comment


              #21
              Spoilt

              Yes I am now spoilt for choice.
              Your command of English is excellent!

              Comment


                #22
                Going so well ...

                and then thud...
                I have spent most of Sunday afternoon trying to solve this riddle.. and I am just not getting it?

                How do I get my PointF or even better the Y co ordinate to place my rectangle?

                Code:
                private StringAlignment BoxX = StringAlignment.Near;
                private StringAlignment BoxY = StringAlignment.Near;
                
                
                //			case BoxPosition.BottomLeft:
                //	
                //			BoxX = StringAlignment.Near;
                //			BoxY = StringAlignment.Far;
                //			line1locale = 32;
                //			line2locale = 16;
                //			break;
                //		}
                line 1 and line 2 are built using StringBuilder and then I use DrawTextAbsolute for the 2 separate lines.

                I measure my largest string

                Code:
                	mySizeF =  graphics.MeasureString(str1,textFontBold);	
                	mySizeF2 = graphics.MeasureString(str2,textFontBold);
                
                       Size mySize = Size.Ceiling(mySizeF);
                       Size mySize2 = Size.Ceiling(mySizeF2);
                
                	int myWidth  = Math.Max(mySize.Width,mySize2.Width);
                        int height = (textFontBold.Height * 2) +5;
                I am then completely confused about how to get the Y start co ordinate.

                Point point1 = new Point(line1locale) doesn't give me the correct value.

                I prefer the integer route so
                If I manually use ChartControl.CanvasTop +2 - that works
                but the bottom is Chartcontrol.CanvasBottom - 289 - I only got this by manually deprecating nos until it looked right.

                There has to be a simple way to get this point as the program has already placed the text - but how do I recover this value???

                Comment


                  #23
                  Hi Mindset,

                  not sure what exactly your problem is, so I try my 2 cents.

                  Your point-structure consists of 2 coordinates, a X and a Y. I would set that in relation to the Canvas.X and Canvas.Y or Canvas.Top and Canvas.Left respectively. These pairs all describe the upper left corner of an rectangle and you could set these pairs into relationship easily.

                  That means:
                  Point.Y = Canvas.Top: Your rectangle is placed at the top edge of your canvas.
                  Point.Y = Canvas.Bottom - myRectangle.Height: Your rectangle is placed at the bottom edge of your canvas.

                  Btw, moving shapes around on a canvas is an exciting untertaking

                  Regards
                  Ralph

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Yesterday, 06:40 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post algospoke  
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  45 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  21 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  181 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X