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 :-)
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!
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
NinjaTrader
length and measure
Collapse
X
-
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 :-)Tags: None
-
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
-
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
-
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
-
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
-
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
-
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:
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
-
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
-
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
-
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);
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 Today, 08:20 PM | ||
Started by md4866, Today, 08:15 PM
|
0 responses
6 views
0 likes
|
Last Post
by md4866
Today, 08:15 PM
|
||
Started by mjbatts91, Yesterday, 04:48 PM
|
2 responses
23 views
0 likes
|
Last Post
by mjbatts91
Today, 07:52 PM
|
||
Workspaces
by pibrew
Started by pibrew, Today, 06:10 PM
|
1 response
19 views
0 likes
|
Last Post Today, 07:31 PM | ||
Started by actualfacts.2021, 07-25-2021, 03:11 PM
|
8 responses
1,187 views
0 likes
|
Last Post
by linkcou
Today, 07:11 PM
|
Comment