NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 02-18-2011, 11:27 AM   #1
keven
Junior Member
 
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Angry About the text format of DrawText method

Dear all,

I am dealing with a text problem. It is that if a want to display a 3*3 ( or other size)
string matrix, for example

string text = "aa b ccc\na bb c\naaa\nbb cc\n"
while using DrawText method, we will get:

aa_b_ccc
a_bb_c
aaa_bb_cc


is there any way that we can get:

aa___b___ccc
a____bb__c
aaa__bb__cc


how to align each column like that?

Thanks
Last edited by keven; 02-18-2011 at 05:37 PM.
keven is offline  
Reply With Quote
Old 02-18-2011, 11:34 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

keven, not sure I follow - what is the difference exactly in your two examples? Could you please clarify for us?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 02-18-2011, 05:42 PM   #3
keven
Junior Member
 
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Oh, sorry, my mistake. the system trim the redundant blanks between the strings automatically.
let me use _ to replace blank. now the example looks like:

aa_b_ccc
a_bb_c
aaa_bb_cc


is there any way that we can get:

aa___b___ccc
a____bb__c
aaa__bb__cc


in other words, how to align the string of each column ?


Thanks
keven is offline  
Reply With Quote
Old 02-18-2011, 05:56 PM   #4
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,205
Thanks: 24
Thanked 1,228 times in 999 posts
Send a message via Skype™ to koganam
Default

Can you not just backpad your strings with spaces to force them to line up?
koganam is online now  
Reply With Quote
Old 02-18-2011, 06:00 PM   #5
keven
Junior Member
 
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

but the thing is I don't know the length of each string.

do we have some method to set the field width of the string ?


Thanks
keven is offline  
Reply With Quote
Old 02-18-2011, 06:04 PM   #6
Dexter
Junior Member
 
Join Date: May 2010
Location: Laramie, WY
Posts: 24
Thanks: 0
Thanked 1 time in 1 post
Default

You can align values in a string fairly easily using String.Format(),
For example, if you want your values to be left padded every 5 spaces (For a,b,c values) you can do something like this:

String.Format("{0, -5} {1, -5} {2, -5}", a,b,c)

For Right aligned, use 5 instead of -5. This will work fine for any integer that is 5 characters or less, feel free to adjust to your needs as 5 might be too wide. You can use \n in the Format or string 3 of them together, whichever is more readable to you. I believe that should work as you desire with DrawText().

edit: I typod (should be 0, 1, 2 like usual in {}) plus here's a full example!
Code:
protected override void OnBarUpdate()
{
    int a = 123;
    int b = 321;
    int c = 12;            
    DrawText("textTag1", String.Format("{0, -5} {1,-5} {2,-5}", a,b,c), 0, Close[0], Color.Red);
    Plot0.Set(Close[0]);
}
Last edited by Dexter; 02-18-2011 at 06:35 PM.
Dexter is offline  
Reply With Quote
Old 02-18-2011, 07:27 PM   #7
keven
Junior Member
 
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Oh, it works !

Thanks very much for your help Dexter !
keven is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with DrawText() to draw text vertically abmninja General Programming 2 10-18-2010 12:51 PM
DrawText method tamas Version 7 Beta General Questions & Bug Reports 2 08-23-2010 12:54 AM
No overload for method 'DrawText' error badasan Version 7 Beta General Questions & Bug Reports 3 05-04-2010 05:13 PM
Display Bug in DrawText Method KBJ General Programming 6 06-12-2009 05:21 AM
Positioning text using DrawText() higler General Programming 7 07-15-2008 01:36 AM


All times are GMT -6. The time now is 10:45 AM.