wpf 如何更改 RichTextBox 段落间距?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/325075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change RichTextBox paragraph spacing?
提问by Darren Oster
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 like to achieve it programmatically if possible. Any ideas?
我在 WPF 中使用 RichTextBox,并尝试将默认段落间距设置为 0(以便没有段落间距)。虽然我可以在 XAML 中做到这一点,但如果可能的话,我想以编程方式实现它。有任何想法吗?
回答by moogs
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>
回答by Ramesh Soni
Using Line Height
使用行高
RichTextBox rtb = new RichTextBox();
Paragraph p = rtb.Document.Blocks.FirstBlock as Paragraph;
p.LineHeight = 10;
回答by Darren Oster
Close, so you got the points. Actually it turned out to be setting the margin,
关闭,所以你得到了积分。其实原来是设置边距,
p.Margin = new Thickness(0);
回答by m4rcel
For me on VS2017 in WPF works this:
对我来说,WPF 中的 VS2017 是这样工作的:
<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"
关键是Block.LineHeight="2"
You can found this also in Properties view but you can't change below 6px from there.
您也可以在“属性”视图中找到它,但不能从那里更改低于 6px。
回答by senquevila
RichTextBox rtb = new RichTextBox();
rtb.SetValue(Paragraph.LineHeightProperty, 1.0);
回答by Danny
In C# 2008 WAP
在 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.
这是您可以拥有行高间距的唯一方法。
回答by Haasan Sachdev
<RichTextBox Height="250" Width="500" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True" >
<Paragraph>
XYZ
<LineBreak />
</Paragraph>
</RichTextBox>