How do I change RichTextBox paragraph spacing?

前端 未结 8 1995
暖寄归人
暖寄归人 2020-12-02 16:21

I am using a RichTextBox in WPF, and am trying to set the default paragraph spacing to 0 (so that there is no paragraph spacing). While I could do this in XAML, I would lik

相关标签:
8条回答
  • 2020-12-02 17:00

    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>
    
    0 讨论(0)
  • 2020-12-02 17:07
    <RichTextBox  Height="250" Width="500" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True" >
        <Paragraph>
            XYZ
            <LineBreak />
        </Paragraph>
    </RichTextBox>
    
    0 讨论(0)
  • 2020-12-02 17:18

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

    p.Margin = new Thickness(0);
    
    0 讨论(0)
  • 2020-12-02 17:19
    RichTextBox rtb = new RichTextBox();
    rtb.SetValue(Paragraph.LineHeightProperty, 1.0);
    
    0 讨论(0)
  • 2020-12-02 17:20

    Using Line Height

    RichTextBox rtb = new RichTextBox();    
    Paragraph p = rtb.Document.Blocks.FirstBlock as Paragraph;    
    p.LineHeight = 10;
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题