c# - html文本到富文本框

时间:2016-07-26 18:56:32

标签: c# html

快速解释我制作一个接收电子邮件的程序然后显示它们,如果它检测到电子邮件中的html,它会将其转换为它在gmail或文本上的外观。要做到这一点,我只是寻找HTML标签并替换它们如下:

        eHtmlText = eHtmlText.Replace("<br>", Environment.NewLine);
        eHtmlText = eHtmlText.Replace("<b>", "\b");
        eHtmlText = eHtmlText.Replace("</b>", "\b0");
        eHtmlText = eHtmlText.Replace("<font color = Black>", "");
        eHtmlText = eHtmlText.Replace("<font color = red>", "");
        eHtmlText = eHtmlText.Replace("<font color = Maroon>", "");
        eHtmlText = eHtmlText.Replace("<font color = blue>", "");
        eHtmlText = eHtmlText.Replace("<font color = DarkBlue>", "");
        eHtmlText = eHtmlText.Replace("<font color = green>", "");
        eHtmlText = eHtmlText.Replace("<font color = grey>", "");
        eHtmlText = eHtmlText.Replace("<font color = purple>", "");
        eHtmlText = eHtmlText.Replace("</font>", "");
        eHtmlText = eHtmlText.Replace("<a href =", "");
        eHtmlText = eHtmlText.Replace("> Click here </a>", "");


        //        HtmlText = HtmlText.Replace("<font color = green>", EmailBody.SelectionColor = Color.Red);
        //      HtmlText = HtmlText.Replace("</font>", EmailBody.SelectionColor = Color.Black);

        EmailBody.Text = eHtmlText;

偶然的事情不起作用,大胆的标签只是被这些带有白色cirlces的黑色方块所取代,而不是如果你知道我的意思那么使文字变粗。颜色工作除了只删除它们的插件我想要实际上使文本颜色。我尝试了注释掉的行,但显然把它放到字符串中是行不通的,我不知道怎么做。 mabye一个字符串数组,用于分割找到标记的字符串,然后单独添加颜色。任何帮助都是适当的

0 个答案:

没有答案