How do I change RichTextBox paragraph spacing?

为君一笑 提交于 2019-11-27 18:40:32

I did it with style (pun indented)

<RichTextBox  Margin="0,51,0,0" Name="mainTextBox" >
        <RichTextBox.Resources>
            <Style TargetType="{x:Type Paragraph}">
                <Setter Property="Margin" Value="0"/>
            </Style>
        </RichTextBox.Resources>
    </RichTextBox>

Using Line Height

RichTextBox rtb = new RichTextBox();    
Paragraph p = rtb.Document.Blocks.FirstBlock as Paragraph;    
p.LineHeight = 10;

Close, so you got the points. Actually it turned out to be setting the margin,

p.Margin = new Thickness(0);

For me on VS2017 in WPF works this:

 <RichTextBox HorizontalAlignment="Left" Height="126" Margin="10,280,0,0" VerticalAlignment="Top" Width="343" FontSize="14" Block.LineHeight="2"/>

The key is Block.LineHeight="2"

You can found this also in Properties view but you can't change below 6px from there.

senquevila
RichTextBox rtb = new RichTextBox();
rtb.SetValue(Paragraph.LineHeightProperty, 1.0);
Danny

In C# 2008 WAP

richtextbox1.SelectionCharOffset =
    -1 * ( Convert.ToInt32(R223.Txt_Space_Before.Text) * 100);

or

richtextbox1.SelectionCharOffset =
    Convert.ToInt32(R223.Txt_Space_Before.Text) * 100;

can be used for Line Spacing.

This is the only way you can have line height spacing.

Haasan Sachdev
<RichTextBox  Height="250" Width="500" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True" >
    <Paragraph>
        XYZ
        <LineBreak />
    </Paragraph>
</RichTextBox>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!