Richtextbox中的不同颜色 [英] Different colors in Richtextbox

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

问题描述

我使用Windows Appliction形式(C#)的richTextBox.
上面写着黑色原色的123456789.
在某些情况下,我将文本(例如:123)的一部分制成红色前景色",在其他情况下,将其设为撤消". (现在再次都是黑色的)

现在的问题是,当我选择12345时,它无法识别所选颜色(IsknownColor = false).但是如果我分别选择文本(例如:123和45).它给出了IsknownColor = True

解决方案


引用 富文本格式

在链接 http://www.functionx.com/vcsharp/controls/richtextbox.htm

而不是检查:SelectedColor.
我使用以下内容:

 如果(RichTextBox1.SelectedRtf.Contains(" ))
                {
        MessageBox.Show(" );
                    返回;
                } 


I hv a richTextBox in Windows Appliction form (C#).
it has some text say:123456789 of black forecolor.
On some event, I make the part of text (say:123) to Red Forecolor and on other event I make it Undo. (Now,again all are black)

Now the problem is that, when I select 12345, it doesnt recognise the selected color(IsknownColor=false). but if I select the text seperately (say: 123 and 45) . It gives IsknownColor=True

解决方案

refer from
Rich Text Formatting

in link http://www.functionx.com/vcsharp/controls/richtextbox.htm


Instead of checking on: SelectedColor.
I hv use following:

if (RichTextBox1.SelectedRtf.Contains("red255"))
                {                    
        MessageBox.Show("Please do not select the already selected text!!");
                    return;
                }


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

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