题
我正在使用WPF一个RichTextBox,并正在尝试默认段落间距设置为0(以使得没有段落间距)。虽然我能做到这一点在XAML,我想如果可以通过编程方式实现这一目标。任何想法?
解决方案
我干的与式强>(双关语缩进)
<RichTextBox Margin="0,51,0,0" Name="mainTextBox" >
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</RichTextBox.Resources>
</RichTextBox>
其他提示
使用行高度
RichTextBox rtb = new RichTextBox();
Paragraph p = rtb.Document.Blocks.FirstBlock as Paragraph;
p.LineHeight = 10;
关闭,所以你得到了点。实际上它原来是设置余量,
p.Margin = new Thickness(0);
有关我在WPF VS2017的工作原理是:
<RichTextBox HorizontalAlignment="Left" Height="126" Margin="10,280,0,0" VerticalAlignment="Top" Width="343" FontSize="14" Block.LineHeight="2"/>
的关键是的 Block.LineHeight = “2”强>
您可以发现,这也是在属性观点,但你可以在下面6个像素从那里不会改变。
RichTextBox rtb = new RichTextBox();
rtb.SetValue(Paragraph.LineHeightProperty, 1.0);
在C#2008 WAP
richtextbox1.SelectionCharOffset =
-1 * ( Convert.ToInt32(R223.Txt_Space_Before.Text) * 100);
或
richtextbox1.SelectionCharOffset =
Convert.ToInt32(R223.Txt_Space_Before.Text) * 100;
可用于行距。
这是可以有白线高度间距的唯一途径。
<RichTextBox Height="250" Width="500" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True" >
<Paragraph>
XYZ
<LineBreak />
</Paragraph>
</RichTextBox>
不隶属于 StackOverflow