Reshma
Reshma

Reputation: 1430

Making specific text bold in a string in C# asp.net

I want make some specific part of a string in bold and bigger in size. Given below is the 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);
}

From the above string, I want to make specific part bold and larger in size. I want TICKET should be bolder and bigger. Help me to find a proper solution. Thank you.

Upvotes: 2

Views: 8018

Answers (3)

Keval Gangani
Keval Gangani

Reputation: 1328

Here it is,

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";

I have update your code, please use it.

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);

Upvotes: 1

Hafiz Adewuyi
Hafiz Adewuyi

Reputation: 378

Simple.

From the '\n' character beside your "TICKET", I presume you want to make it the title text of your document.

To do this, I would simply surround the title text with a 'h4' HTML tag like below:

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

Upvotes: 1

Nemox42
Nemox42

Reputation: 139

It all depends on what your trying to display it in. If you are trying to display the string in a label, textbox, etc. You can use the properties window, in visual studio, select the label, textbox etc, then click on the font cell, click on the ... next to it and it lets you bold/change font style/size. Hope this helps.

Upvotes: 0

Related Questions