Header.Text text wrapping?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tjip
Newbie
Newbie
Posts: 4
Joined: Wed Feb 06, 2008 12:00 am

Header.Text text wrapping?

Post by tjip » Wed Jul 02, 2008 1:32 pm

Hi,

My teechartcontrol.Header.Text is set dynamic and sometimes i have a long text (doesnt fit in the screen). is it possible to make the Header.Text auto wrap it self? is there any command for that?

if now, what is a possible solusion?

Regards,

M.Ismail

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jul 02, 2008 1:48 pm

Hi M.Ismail,

Yes, you can try doing something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();		
		}

		private void InitializeChart()
    {
			tChart1.Width = 150;
			tChart1.Header.Text = WrapHeaderText("an extremely long chart header which doesn't fit in chart control's width");
    }

		private string WrapHeaderText(string text)
		{
			string tmpStr = text;
			SizeF titleDims = tChart1.Graphics3D.MeasureString(tChart1.Header.Font, tmpStr);

			while (titleDims.Width > tChart1.Width)
			{
				int tmp = tmpStr.LastIndexOf(" ");
				tmpStr = tmpStr.Substring(0, tmp) + "\n" + tmpStr.Substring(tmp + 1).Replace("\n", " ");
				titleDims = tChart1.Graphics3D.MeasureString(tChart1.Header.Font, tmpStr);
			}

			return tmpStr;
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jul 02, 2008 2:18 pm

Hi M.Ismail,

As an update, I'm also posting a recursive version of WrapHeaderText method:

Code: Select all

		private string WrapHeaderText(string text)
		{			
			SizeF titleDims = tChart1.Graphics3D.MeasureString(tChart1.Header.Font, text);

			if (titleDims.Width > tChart1.Width)
			{
				int tmp = text.LastIndexOf(" ");
				string tmpStr = text.Substring(0, tmp) + "\n" + text.Substring(tmp + 1).Replace("\n", " ");
				return WrapHeaderText(tmpStr);
			}
			else
			{
				return text;
			}
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tjip
Newbie
Newbie
Posts: 4
Joined: Wed Feb 06, 2008 12:00 am

thanks

Post by tjip » Thu Jul 03, 2008 12:36 pm

thank you for the fast replay

Post Reply