在C#asp.net中的字符串中使特定文本变为粗体

时间:2015-03-28 07:20:25

标签: c# asp.net string

我希望以粗体和更大的尺寸制作字符串的某些特定部分。以下是字符串。

{
-----
-----
    string body = "TICKET \n";body += "Category : " + Category + "\n";
    body += "Priority : " + priority + "\n";body += "Type : " + type + "\n";
    var smtp = new System.Net.Mail.SmtpClient();
    {
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
    smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
}

从上面的字符串中,我想使特定部分变粗并且尺寸更大。我希望TICKET应该更大胆。帮我找一个合适的解决方案。谢谢。

3 个答案:

答案 0 :(得分:1)

在这里,

string body = "<span style='font-weight:bold;font-size:25px;'>TICKET</span> \n";body += "Category : " + Category + "\n";
body += "Priority : " + priority + "\n";body += "Type : " + type + "\n";

我已更新您的代码,请使用它。

string body = "TICKET \n"; body += "Category : " + "Category" + "\n";
    body += "Priority : " + "priority" + "\n"; body += "Type : " + "type" + "\n";

    MailMessage objMailMessage = new MailMessage();
    System.Net.NetworkCredential objSMTPUserInfo = new System.Net.NetworkCredential();
    SmtpClient objSmtpClient = new SmtpClient();

    objMailMessage.From = new MailAddress(fromAddress);
    objMailMessage.To.Add(new MailAddress(toAddress));
    objMailMessage.Subject = subject;
    objMailMessage.Body = body;
    objMailMessage.IsBodyHtml = true;

    objSmtpClient.Host = "smtp.gmail.com";
    objSmtpClient.Port = 587;
    objSmtpClient.EnableSsl = true;
    objSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
    objSmtpClient.Credentials = new NetworkCredential(fromAddress, fromPassword);
    objSmtpClient.Timeout = 20000;

    objSmtpClient.Send(objMailMessage);

答案 1 :(得分:0)

这完全取决于您尝试显示它的内容。如果您尝试在标签,文本框等中显示字符串。您可以使用属性窗口,在visual studio中选择标签,文本框等,然后单击字体单元格,单击旁边的...,它可以让您加粗/更改字体样式/大小。希望这可以帮助。

答案 2 :(得分:0)

简单。

从“TICKET”旁边的'\ n'字符开始,我认为您希望将其作为文档的标题文本。

要做到这一点,我只需用'h4'HTML标签包围标题文字,如下所示:

string body = "<h4>TICKET</h4>";body += "Category : " + Category + "\n";
body += "Priority : " + priority + "\n";body += "Type : " + type + "\n";