找回密码
 立即注册

QQ登录

只需一步,快速开始

etsoft

中级会员

31

主题

84

帖子

593

积分

中级会员

积分
593

活字格认证

etsoft
中级会员   /  发表于:2013-12-19 23:16  /   查看:5993  /  回复:9
打开的文件,以前有文本,现在希望新插入的文字加上背景色,该如何实现?谢谢

9 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-12-20 13:58:00
沙发
回复 1楼etsoft的帖子

etsoft 你好,
可以通过 Selection.TextBackColor 属性设置文本背景色。
回复 使用道具 举报
etsoft
中级会员   /  发表于:2013-12-20 22:33:00
板凳
我想的是,新增的字符都使用某一种背景色,不用选中
我试了版主的方法,如果是空白的文档,就没问题,但如果打开时加载有文本内容,则不生效了
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-12-23 12:19:00
地板
回复 3楼etsoft的帖子

了解你的需求了,请参考Demo:

11414.zip (181.35 KB, 下载次数: 297)
回复 使用道具 举报
etsoft
中级会员   /  发表于:2013-12-23 12:54:00
5#
看了demo,用了两个语句来实现:
            this.textControl1.InputFormat.TextColor = Color.Red;
          this.textControl1.InputFormat.TextBackColor = Color.Green;
加了这两个语句后,在文档的最后增加文字可以实现背景色或改变文字的颜色,但在原来的文要中间插入的时候,所取得的格式是插入点位置的格式,如何改变插入点的格式呢?
回复 使用道具 举报
etsoft
中级会员   /  发表于:2013-12-23 16:53:00
6#
可以解决吗?就是不管插入点移到什么位置,都使用一种文本格式
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-12-23 17:50:00
7#
回复 6楼etsoft的帖子

可以解决,需要先获取当前选择位置文本样式,再设置给 TX :

  1.         private void textControl1_InputPositionChanged(object sender, EventArgs e)
  2.         {

  3.             TXTextControl.InputPosition ip = this.textControl1.InputPosition;
  4.             this.textControl1.Select(ip.TextPosition, 1);
  5.             this.textControl1.InputFormat.TextColor = this.textControl1.Selection.ForeColor;
  6.             this.textControl1.InputFormat.TextBackColor = this.textControl1.Selection.TextBackColor;
  7.             this.textControl1.Select(ip.TextPosition, 0);
  8.         }
复制代码
回复 使用道具 举报
etsoft
中级会员   /  发表于:2013-12-24 13:13:00
8#
非常感谢
回复 使用道具 举报
etsoft
中级会员   /  发表于:2013-12-24 13:14:00
9#
可以结贴了
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-12-24 16:20:00
10#
回复 9楼etsoft的帖子

不客气,有问题欢迎开新帖提问。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部