richtextbox控件中操作行间距段间距都可以用发送消息解决,但是字间距却鲜有人关注,无法通过PARAFORMAT2消息解决,只能直接操作rtf格式

字间距主要就是要控制 expand expandtw 这些rtf属性

下面给出一个插入代码,只能对简单点的rtf进行操作,word保存出来的rtf不一定可以

操作rtf格式的类库使用RtfTree

        public void SetCharacterSpacing(int spacing)
{
spacing--;
if (spacing < 0)
{
return;
} RtfTree doc = new RtfTree();
doc.LoadRtfText(this.Rtf);
RtfNodeCollection fileds = doc.MainGroup.ChildNodes;
bool hasltrch = false;
bool hasrtlch = false;
bool hasText = !string.IsNullOrEmpty(this.Text);
foreach (RtfTreeNode f in fileds)
{
if (f.NodeType == RtfNodeType.Keyword)
{
if (f.NodeKey == "expnd")
{
f.Parameter = spacing;
}
if (f.NodeKey == "expndtw")
{
f.Parameter = spacing * 5;
}
if (f.NodeKey == "ltrch")
{
hasltrch = true;
}
if (f.NodeKey == "rtlch")
{
hasrtlch = true;
}
} } if (spacing > 0)
{
if (hasText)
{
bool ispar = false; for (int i = fileds.Count - 1; i >= 0; i--)
{
var f = fileds[i];
if (f.NodeKey == "par")
{
ispar = true; }
if (f.NodeKey == "u" || f.NodeKey == "'" || f.NodeType == RtfNodeType.Text)
{
continue;
}
else
{
if (ispar)
{
if (fileds[i - 1].NodeKey.Contains("expnd"))
{
continue;
}
InsertLetterExpand(spacing, doc, f.Index);
ispar = false;
}
}
if (f.NodeType == RtfNodeType.Group)
{
if (f.ChildNodes[0].NodeKey == "colortbl" || f.ChildNodes[0].NodeKey == "fonttbl")
{
if (!doc.MainGroup[f.Index + 1].NodeKey.Contains("expnd"))
{
InsertLetterExpand(spacing, doc, f.Index + 1);
i -= 2;
}
else
{
continue;
} }
}
if (f.NodeKey == "viewkind")
{
if (!doc.MainGroup[f.Index - 1].NodeKey.Contains("expnd"))
{
InsertLetterExpand(spacing, doc, f.Index);
i--;
}
continue;
}
}
}
else
{
for (int i = fileds.Count - 1; i >= 0; i--)
{
var f = fileds[i];
if (f.NodeKey == "par")
{
InsertLetterExpand(spacing, doc, f.Index - 1);
break;
}
}
}
} if (!hasltrch)
{
doc.MainGroup.InsertChild(1, new RtfTreeNode(RtfNodeType.Keyword, "ltrch", false, 0));
}
if (!hasrtlch)
{
doc.MainGroup.InsertChild(1, new RtfTreeNode(RtfNodeType.Keyword, "rtlch", false, 0));
} this.Rtf = doc.Rtf;
} private void InsertLetterExpand(int spacing, RtfTree doc, int index)
{
doc.MainGroup.InsertChild(index, new RtfTreeNode(RtfNodeType.Keyword, "expnd", true, spacing));
doc.MainGroup.InsertChild(index, new RtfTreeNode(RtfNodeType.Keyword, "expndtw", true, spacing * 5));
}

  

rtf格式 C#设置字间距 CharacterSpacing的更多相关文章

  1. NSAttributedString之设置字间距与行间距

    // 调整行间距 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithSt ...

  2. UILabel设置行间距和字间距并计算高度-b

    #define UILABEL_LINE_SPACE 6 #define HEIGHT [ [ UIScreen mainScreen ] bounds ].size.height //给UILabe ...

  3. Lodop设置文本项行间距、字间距

    LODOP给文本项ADD_PRINT_TEXT设置字间距.行间距,可以在打印设计页面,右键属性里设置,然后在打印设计生成代码,也可以直接写代码.LineSpacing行间距.LetterSpacing ...

  4. iOS UILabel设置行间距和字间距

    实现UILabel的文字,设置行间距和字间距. 效果图: 代码: let lblTitle = UILabel(frame: CGRect(x: , y: , width: KScreenWidth- ...

  5. [图片问答]LODOP打印的行间距字间距

    LODOP可以打印纯文本,也可以是超文本,关于哪些打印项是纯文本,哪些打印项是超文本,之前有博文相关介绍:LODOP中的纯文本和超文本打印项. 之前的关于纯文本的行间距字间距介绍:Lodop设置文本项 ...

  6. 使用CSS设置行间距,字间距.

    字间距1.text-indent设置抬头距离css缩进即对,对应div设置css样式text-indent : 20px; 缩进了20px 2.letter-spacing来设置字与字间距_字符间距离 ...

  7. css 字间距、CSS字体间距、css 字符间距设置

    1.text-indent设置抬头距离css缩进 2.letter-spacing来设置字与字间距_字符间距离,字体间距css样式

  8. textview设置字体的行距和字间距

    字间距 textView有一个属性android:textScaleX是调节字间距的,它的值是一个float型.查看源代码,默认textView 此属性是使用的是: android.internal. ...

  9. css如何设置label的字间距

    css.html如何设置label的字间距 .myClass  label{ letter-spacing: 10px; } 如果label需要居中,需加上 text-indent: 10px; 首行 ...

随机推荐

  1. 分布式锁三种实现方式(DB,redis,zookeeper)比较

    先贴出看到的一篇博客,后续补充自己总结分析的. https://blog.csdn.net/u010963948/article/details/79006572

  2. Python:每日一题004

    题目: 输入某年某月某日,判断这一天是这一年的第几天? 程序分析: 以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于2时需考虑多加一天 个人的思路及 ...

  3. Apache beam中的便携式有状态大数据处理

    Apache beam中的便携式有状态大数据处理 目标: 什么是 apache beam? 状态 计时器 例子&小demo 一.什么是 apache beam? 上面两个图片一个是正面切图,一 ...

  4. RDS MySQL InnoDB 锁等待和锁等待超时的处理

    https://help.aliyun.com/knowledge_detail/41705.html 1. Innodb 引擎表行锁等待和等待超时发生的场景 2.Innodb 引擎行锁等待情况的处理 ...

  5. sql server中replace()函数用法解析

    知识点一:replace()的语法 REPLACE ( string_replace1 , string_replace2 , string_replace3 ) 参数解析: string_repla ...

  6. 网页打印样式CSS

    相信大多数的前端工程师都是处理显示屏上面的设计,用到最多的计量单位就是px,但是有些时候,我们难免也会有打印的需求,比如一个电商平台的“物流配送打印单”,“打印订单”等等可能都是需要从网友上打印出来的 ...

  7. bug的一些事

    Bug级别:(由高到低) 1.critical:系统直接崩溃,瘫痪.无法正常打开使用产品 2.Block:逻辑出现严重问题,流程卡住,无法进行下一步 3.Major:部分功能出现闪退,功能没有实现,但 ...

  8. PowerShell 命令行调试指引(转)

    How to manage a debugging session Before you start debugging, you must set one or more breakpoints. ...

  9. QQ网页弹窗

    QQ网页弹窗 1.网址:http://shang.qq.com/v3/index.html 2.选推广工具,提示语随便写 3.建一个html 网页,并把代码拷进去. 4.双击网页,就可以打开了.(用E ...

  10. 配置docker官方源并用yum安装docker

    一.docker的官方安装文档: https://docs.docker.com/engine/installation/linux/centos/ 由docker给的文档可以看出它也只是去配置了一个 ...