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

    length and measure

    Could someone please explain how to convert a text.length to the correct value for a rectangle width?

    The int value is 28 which is the no of characters but my rectangle is 28 pixels - I think. I have looked through msdn but it is just defeating me and I know it will be simple :-)

    #2
    Unfortunately this is beyond the support we can provide. Hopefully another forum member with experience in this area can help you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Mindset, you have to use ChartGraphics.MeasureString(...) for that purpose.

      Regards
      Ralph

      Comment


        #4
        Still not there

        Hi Ralph

        That is what I thought with my research but I am missing a piece of the puzzle

        width = ChartGraphics.MeasureString(tempstr , textFontBold);

        I get the error that graphics doesn't exist. I have a plot override but this statement is outside it - is that not ok?


        Could you show an example?

        Comment


          #5
          Hi Mindset,

          I made a mistake in my description. "ChartGraphics" is the name of a local variable, and therefore meaningless to you. "ChartGraphics" is the reference to first parameter of the Plot() method (Graphics object). Finally I use "ChartGraphics" outside Plot(), but I set it inside Plot(), every time Plot() is invoked.

          Regards
          Ralph

          Comment


            #6
            half understand

            Ralph

            I think I sort of get some of what you are saying. Having had no formal programme training my knowledge is mostly from library books and cutting/pasting other people's code to fit together to do what I want it to do.

            I have learnt to a very basic level along the way.

            There is in fact a ChartGraphics.Graphics Property ( just to add to the confusion in my head) on msdn (lol).

            I shall get there in the end but your comment about outside plot() and inside plot every time it's invoked left me puzzled.

            Comment


              #7
              Hi Mindset,

              I appreciate your comment.
              Let's clarify some of the issues. The first is: I can't find a "ChartGraphics" in the MSDN Doc. Do you have a link for that?

              Regards
              Ralph

              Comment


                #8
                chartgraphics

                I found that property here

                I am a teensie bit further forward.
                I have moved my string to the variables section and I can now get a SizeF.

                I understand this to give 4 floating point nos delineating the string in a box (rectangle)

                When I then try and define a new rectangle it says it can't convert from float to int?? Ha Ha!!

                Comment


                  #9
                  How do you want to use the SizeF? To create an rectangle? Is your system based on double, float, or integer?

                  Regards
                  Ralph

                  Comment


                    #10
                    rectangle

                    Appreciate this Ralph. My SizeF is called stringsize.

                    I assumed this would work if I created a rectangle using SizeF

                    Rectangle rect = new Rectangle(5,stringsize.Height,stringsize.Width,tex tFontBold.Height);

                    params 2 and 3 are the problem. 1 and 4 seem fine.

                    My reference book (Learn c# in 21 days (Sams)) has no info on this either.

                    I am just not getting the whole concept here - does SizeF not contain all the info necessary to create a whole rectangle as it holds 4 points?

                    On msdn it looks like I should use RectangleF and then just add a start point

                    eg RectangleF rectF =
                    new RectangleF(myLocation, stringSize);

                    but that doesn't work either.

                    You can probably sense I am getting quite frustrated with this.
                    Last edited by Mindset; 11-14-2009, 11:39 AM.

                    Comment


                      #11
                      Hi Mindset,

                      hard to judge at which day they would teach the SizeF in their books, obviously after day 21 :|

                      Let's make an end with your frustration.
                      SizeF contains 2 values, what ever that means, you could use such structure whereever you need a value pair. These values are float. A RectangleF needs 4 coordinates or a PointF and a SizeF:
                      Stores a set of four floating-point numbers that represent the location and size of a rectangle. For more advanced region functions, use a Region object.

                      I guess myLocation isn't a SizeF?
                      Rectangle needs 4 coordinates or a Point and a Size, all integers:
                      Stores a set of four integers that represent the location and size of a rectangle.


                      I do operate with integers preferable. If you do too, I would recommend to convert the SizeF to a Size and then your Rectangle-Construction should work. Here are 2 examples how to convert:
                      SizeF strSizeF = Graphics.MeasureString(str, stringFont);
                      Size strSize = Size.Ceiling(strSizeF);
                      Size strSize = Size.Truncate(strSizeF);

                      Let me know, if that works.

                      Regards
                      Ralph

                      Comment


                        #12
                        Update

                        Ralph

                        Apologies - have been away and still struggling with this Size and SizeF thing.
                        appreciate all your help but I will take this info, go into my cave, and try and get it all right in my head.

                        Comment


                          #13
                          Inching forward

                          ok - I have started to get some of the concepts of the rectangle. Still don't get what the difference is between canvas and bounds. Actually I don't really get bounds either but never mind - I can use it.


                          Thanks for the explanation of coridinates vs integers - that was a major stumbling block for me before you explained so succinctly.
                          my problem now is the width of the string. i am using stringbuilder to compose a string and my size keeps getting a very small measurement.
                          I am measuring as the stringbuilder is finished - is there something special I am missing/ need to do?

                          Comment


                            #14
                            Hi Mindset,

                            bounds is the rectangle describing the dimension of your canvas, nothing more. The graphics object is the instantiation of a graphical class containing all the functionality needed for the interaction with the canvas (i.e. measurestring()).

                            Measurestring returns that SizeF structure, wich contains 2 values. One is the width and one is the hight of your string. Since you have to hand over a font object as second parameter, MeasureString() knows how to calculate the width correctly. It doesn't matter with which tools you constructed the string.

                            Regards
                            Ralph

                            Comment


                              #15
                              Disappearing up my own smoke

                              Hi Ralph

                              Just spent a v frustrating hour or so with this.

                              Code:
                              int height2 = (textFontBold.Height * 3);
                              width3 =  graphics.MeasureString(incomingpath ,textFontBold);	//SizeF
                              int pointx = ChartControl.Bounds.Left;
                              int pointy = ChartControl.Bounds.Top;
                              int width4 = Size.Ceiling(width3);// error??
                              Rectangle rectangle1 = new Rectangle(pointx,pointy,width4,height2);
                              graphics.DrawRectangle(borderPen,rectangle1);
                              I get an implicit conversion error on the width4 variable.
                              Last edited by Mindset; 11-24-2009, 11:16 AM. Reason: slight code adj

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by set2win, 08-04-2021, 09:23 AM
                              39 responses
                              1,000 views
                              0 likes
                              Last Post WaleeTheRobot  
                              Started by md4866, Today, 08:15 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post md4866
                              by md4866
                               
                              Started by mjbatts91, Yesterday, 04:48 PM
                              2 responses
                              23 views
                              0 likes
                              Last Post mjbatts91  
                              Started by pibrew, Today, 06:10 PM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by actualfacts.2021, 07-25-2021, 03:11 PM
                              8 responses
                              1,187 views
                              0 likes
                              Last Post linkcou
                              by linkcou
                               
                              Working...
                              X