简体   繁体   English

富文本框中的粗体或普通文本

[英]Bold or normal text on the rich text box

I'm doing a project and part of is to. 我正在做一个项目,一部分是去。

if the line number of the rich text box is odd, I want the text to make bold, else the line number is even number I want write text normal. 如果富文本框的行号是奇数,则我希望文本加粗,否则行号是偶数,我要正常写文本。 How can i do this? 我怎样才能做到这一点?

Output must be like this: 输出必须是这样的:

line number 1 (odd) 行号1(奇数)

line number 2 (even) 第2行(偶数)

line number 3 (odd) 第3行(奇数)

line number 4 (even) 行号4(偶数)

My English is not so good, sorry. 对不起,我的英语不太好。

Use RichTextBox.SelectionFont 使用RichTextBox.SelectionFont

int SelectionStart = richtextbox1.SelectionStart; //Start of bold text
int SelectionLenght = richtextbox1.SelectionLength; //End of bold text

// Set font of selected text
// You can use FontStyle.Bold | FontStyle.Italic to apply more than one style
richtextbox1.SelectionFont = new Font(richtextbox1.Font, FontStyle.Bold);

// Set cursor after selected text
richtextbox1.SelectionStart = richtextbox1.SelectionStart + richtextbox1.SelectionLength;
richtextbox1.SelectionLength = 0;
// Set font immediately after selection
richtextbox1.SelectionFont = richtextbox1.Font;

// Reselect previous text
richtexbox1.Select(SelectionStart, SelectionLength);

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

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