-1

I want to center some of the strings.

I saw it.

https://documentation.devexpress.com/WindowsForms/9536/Controls-and-Libraries/Editors-and-Simple-Controls/Simple-Editors/Examples/How-to-Format-Text-in-LabelControl-Using-HTML-Tags

So, I wrote this code.

        labelControl1.Text = "<div style=\"text-align:center;\">center</div><br>" +
                                    "<size=14>Size = 14<br>" +
                                    "Bold <i>Italic</i> <u>Underline</u><br>" +
                                    "<color=255, 0, 0>Sample Text</color></size>";
        labelControl1.AllowHtmlString = true;
        labelControl1.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
        labelControl1.Appearance.Options.UseTextOptions = true;
        labelControl1.AutoSizeMode = LabelAutoSizeMode.Vertical;

But, it didn't work.

enter image description here

What is the problem with it?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Rachel
  • 27
  • 7

2 Answers2

2

According to the documentation, only specific HTML tags are supported, and div is not in the list.

Depending on your requirements, you might split the text into two labels, one centered (AutoSize=False, TextAlign=MiddleCenter) and one with HTML.

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36
  • I thought of this, but I was using a common form and wanted to change the string only. Thanks for the reply. – Rachel Dec 27 '18 at 07:23
2

According to HTML Text Formatting documentation, LabelControl.AllowHtmlString property support these tags and "pseudotags" (tags which not exist in current HTML standard but can be used for rendering purpose in label control):

Normal HTML tags

  • <b> - bold text

  • <i> - italic text

  • <s> - strikethrough

  • <u> - underline

  • <br> (current HTML equivalent is <br />)

Pseudotags

  • <color> (equivalent to CSS color)

  • <backcolor> (equivalent to CSS background-color)

  • <size> (equivalent to CSS font-size)

  • <image=value> (equivalent to HTML <img src="value">)

  • <href=url> (equivalent to HTML <a href="url">)

  • <nbsp> (equivalent to HTML &nbsp;)

The HTML <div> tag is not included in supported tags mentioned above, hence it will rendered as standard text instead.

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61