Page 1 of 1

Header.Text text wrapping?

Posted: Wed Jul 02, 2008 1:32 pm
by 13048237
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

Posted: Wed Jul 02, 2008 1:48 pm
by narcis
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;
		}

Posted: Wed Jul 02, 2008 2:18 pm
by narcis
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;
			}
		}

thanks

Posted: Thu Jul 03, 2008 12:36 pm
by 13048237
thank you for the fast replay