Bold in RichtextBox

前端 未结 2 1248
庸人自扰
庸人自扰 2021-01-06 18:26

I\'ve been working on my richtextbox but I ran into something weird... I want to make the first word on everyline bold

using this code:

        RichT         


        
2条回答
  •  清歌不尽
    2021-01-06 19:29

    My richtextbox wasn't selecting all the occurrences if they weren't sent to my bolding function in the right order; so my fix includes checking that start (srt) is greater than 0 before starting the text selection. It goes something like this:

    foreach (string line in bold.Lines)
    {
        int srt = bold.Find(name);
        if (srt > 0)
        {
            bold.Select(srt, name.Length);
            bold.SelectionFont = new System.Drawing.Font(bold.Font, FontStyle.Bold);
        }
    }
    

    And now it'll always select the first occurrence.

    PS: name is a string, and bold is a RichTextBox.

提交回复
热议问题