11058 : I am trying to add 2 texts to a time item. I want to be able to show text1 on one line and text2 on the line below text1. How can I accomplish this?

Question

 

I am trying to add 2 texts to a time item. I want to be able to show text1 on one line and text3 on the line below text1. I have tried the code below but only the last text gets displayed. How can I accomplish this?

 

Answer

 

To accomplish this use two TimeItemTextLayouts with different padding. The second one should have a top padding to make it appear under the first one:

 

      TimeItemText titxt = new TimeItemText();
      titxt.Text = “Test”;
      titxt.TimeItemTextLayout =
      gantt1.TimeItemTextLayouts.GetFromName(“Default”);
      titxt.TimeItemTextLayout.Color = Color.Black;
      titxt.TimeItemTextLayout.Font = new Font(FontFamily.GenericMonospace, 10, FontStyle.Regular);
      titxt.TimeItemTextLayout.VertAlign = StringAlignment.Near;
      ti.TimeItemTexts.Add(titxt);

 

      TimeItemText titxt2 = new TimeItemText();
      titxt2.Text = “Test2”;
      titxt2.TimeItemTextLayout = gantt1.TimeItemTextLayouts.GetFromName(“Default”).Clone() as TimeItemTextLayout;
      titxt2.TimeItemTextLayout.Name = “SecondOne”;
      gantt1.TimeItemTextLayouts.Add(titxt2.TimeItemTextLayout);
      titxt2.TimeItemTextLayout.Padding=new Rectangle(0,20,0,0);
      ti.TimeItemTexts.Add(titxt2);

Leave a Reply