如何改变新增的文本背景色?
打开的文件,以前有文本,现在希望新插入的文字加上背景色,该如何实现?谢谢 回复 1楼etsoft的帖子etsoft 你好,
可以通过 Selection.TextBackColor 属性设置文本背景色。 我想的是,新增的字符都使用某一种背景色,不用选中
我试了版主的方法,如果是空白的文档,就没问题,但如果打开时加载有文本内容,则不生效了 回复 3楼etsoft的帖子
了解你的需求了,请参考Demo:
看了demo,用了两个语句来实现:
this.textControl1.InputFormat.TextColor = Color.Red;
this.textControl1.InputFormat.TextBackColor = Color.Green;
加了这两个语句后,在文档的最后增加文字可以实现背景色或改变文字的颜色,但在原来的文要中间插入的时候,所取得的格式是插入点位置的格式,如何改变插入点的格式呢? 可以解决吗?就是不管插入点移到什么位置,都使用一种文本格式 回复 6楼etsoft的帖子
可以解决,需要先获取当前选择位置文本样式,再设置给 TX :
private void textControl1_InputPositionChanged(object sender, EventArgs e)
{
TXTextControl.InputPosition ip = this.textControl1.InputPosition;
this.textControl1.Select(ip.TextPosition, 1);
this.textControl1.InputFormat.TextColor = this.textControl1.Selection.ForeColor;
this.textControl1.InputFormat.TextBackColor = this.textControl1.Selection.TextBackColor;
this.textControl1.Select(ip.TextPosition, 0);
}
非常感谢 可以结贴了 回复 9楼etsoft的帖子
不客气,有问题欢迎开新帖提问。
页:
[1]