大胆的RichTextBox [英] Bold in RichtextBox

查看:85
本文介绍了大胆的RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直对我的RichTextBox的,但我遇到了一些奇怪...
我想用

要做出大胆everyline



的第一个字这段代码:

  RichTextBox的大胆= richTextBox1; 
的foreach(在bold.Lines串线)
{
字符串名称= line.Split('')[0];
INT SRT = bold.Find(名);
bold.Select(SRT,name.Length);
bold.SelectionFont =新字体(bold.Font,FontStyle.Bold);
}



但由于某些原因,一些行被跳过。
从我注意到它取决于行开头用什么词



如名称:被跳过,但名1:优良,情况与此相同的ProcessID,VirtualSize和WorkingSetSize。





如果需要更多的解释,请告诉我。



该行被添加像

  richTextBox1.Text + =名称:+ queryObj [名称] + Environment.NewLine; 



让所有的第一句话就是大胆的所有内容将被添加到RichTextBox中后调用的函数。


解决方案

行...

  INT SRT = bold.Find(名); 



...是找到开头的行字的第一次出现。如果你看看那些没有被设置大胆的话,那么你会发现他们都在前面的富文本框中会出现。


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:

        RichTextBox bold = richTextBox1;
        foreach (string line in bold.Lines)
        {
            string name = line.Split(' ')[0];
            int srt = bold.Find(name);
            bold.Select(srt, name.Length);
            bold.SelectionFont = new Font(bold.Font, FontStyle.Bold);
        } 

But for some reason some lines are skipped. From what I noticed it depends on what word the line starts with

e.g Name: gets skipped but Name1: is fine, the same happens with ProcessId, VirtualSize and WorkingSetSize.

If any more explanation is required please tell me.

The lines are added like

richTextBox1.Text += "Name: "+ queryObj["Name"] + Environment.NewLine;

the function to make all first words bold is called after all the content is added to the richtextbox.

解决方案

The line...

int srt = bold.Find(name);

...is finding the first occurrence of the word that starts the line. If you look at the words that haven't been set bold then you will see that they all occur earlier in the rich text box.

这篇关于大胆的RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆