I am formatting the TextColumnName of a TextStyle to include two columns with a line break in between so they display on two lines of text. In ThinkGeo 2.x we could center justify a label. Now it appears that has been removed from the API. Do I need to have a custom TextStyle to achieve this? I need it to display like this:
{1}
15.68
instead of:
{1}
15.68
Formatting Multiline Label
Hi Chad,
I didn’t find any Api for the case in Map Suite 7.0, but I got a workaround by filling the space in the shorter line string at the header. Here is the codes:
TextStyle multiLineTextStyle = TextStyles.CreateSimpleTextStyle("[CNTRY_NAME]\n[POP_CNTRY]", “Arial”, 10, DrawingFontStyles.Bold, GeoColor.SimpleColors.Black);
multiLineTextStyle.Formatting += new System.EventHandler<
FormattingPositionStyleEventArgs
>(multiLineTextStyle_Formatting);
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = multiLineTextStyle;
…
void multiLineTextStyle_Formatting(object sender, FormattingPositionStyleEventArgs e)
{
string[] subTexts = e.Text.Split(new string[] { “\r\n”, “\n” }, StringSplitOptions.None);
int maxLength = subTexts[0].Length;
foreach (var item in subTexts)
{
if (maxLength <
item.Length
)
maxLength
=
item
.Length;
}
StringBuilder
sb
=
new
StringBuilder();
for (int
i
=
0
; i < subTexts.Length; i++)
{
int spaceCount = (maxLength - subTexts<i>.Length)/2;
StringBuilder
spaceString
=
new
StringBuilder();
if (spaceCount > 0)
{
while (spaceCount > 0)
{
spaceString.Append(" ");
spaceCount–;
}
}
sb.Append(spaceString.ToString());
sb.Append(subTexts<i>);
if (i != (subTexts.Length - 1))
sb.AppendLine();
}
e.Text = sb.ToString();
}
I don’t have too much experiences on ThinkGeo 2.x Api, would you let me know how you use in Thinkgeo 2.x to make the labels center with multicolumns?
Hope it helps.
Thanks,
Troy
Hi Troy,
Thanks a lot for the code sample. That accomplishes what I’m looking for. I missed the Formatting event on the text style. ThingGeo 2.x had a StringFormat property on it’s TextStyle. This came from the System.Drawing namespace and it had an Alignment property where you could specify Center. Thanks again!
Chad
Hi Chad,
Oh, yes. We did remove this property since ThinkGeo 3.x but I have no idea what’s the reason. But Still good to hear the workaround is fit for you.
Any other questions, don’t hesitate to let me know.
Thanks,
Troy