简体   繁体   English

富文本框中的新行

[英]New line in rich text box

This is the code which i'm using to send a mail. 这是我用来发送邮件的代码。

It is working fine but problem is line breaks and white spaces are automatically getting removed. 它工作正常,但问题是换行符和空白被自动删除。

Egif I type Good then 10 spaces and then Afternoon in richtextbox and send a mail then at receiver side it look like Good Afternoon means it keeps only one space But i want send mail as it is how sender typed. Egif我先输入Good,然后输入10个空格,然后在richtextbox中输入Afternoon并发送邮件,然后在接收方,它看起来像Good Afternoon,意味着它仅保留一个空格,但是我想发送邮件,因为发送方是这​​样键入的。

var client = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network };

var message = new MailMessage();

message.To.Add(to_textBox.Text);

message.From = new MailAddress(from_textBox.Text);

message.Subject = subject_textBox.Text;

message.IsBodyHtml = true;

string start = "<html><p  style="+'"'+"font-family:'"+fontDialog1.Font.FontFamily.Name+"';"+"font-size:'"+fontDialog1.Font.Size+"'"+'"'+"align="+'"'+message_richTextBox.SelectionAlignment+'"'+">"+message_richTextBox.Text+"</p>"+"</html>";

message.Body = start;

client.Send(message);

Change 更改

message_richTextBox.Text

To: 至:

message_richTextBox.Text.Replace("  ", "&nbsp; ").Replace("\n", "<br>");

&nbsp; is non-breaking space , and <br> is linebreak in html 不间断的空格 ,而<br>是html中的换行符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM