如何限制 RichTextBox 中每行最多 83 个字符 [英] How to limit to max 83 Chars per single line in RichTextBox

查看:35
本文介绍了如何限制 RichTextBox 中每行最多 83 个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 WPF RichTextBox 和 Toolbar 重新创建 MSWord,因此最近的问题之一如下:

Im trying to make a recreation of MSWord using WPF RichTextBox and Toolbar, so one of the recently issues is the following:

在 MSWord 文档中...

In MSWord document...

...with Font Family Times New Roman, 11, Justify a single line contains 95 Chars...使用字体系列 Times New Roman, 11, Justify, Bold 一行包含 83 个字符

...with Font Family Times New Roman, 11, Justify a single line contains 95 Chars ...with Font Family Times New Roman, 11, Justify, Bold a single line contains 83 Chars

关于利润率更推荐使用边距或每行限制字符?原因当用户输入是 , 时.或其他 ASCII 的大小比其他的短,单行更改"中的最大字符数.因此,如果使用边距是最合适的 - WPF RichTextBox 如何管理边距?

about margins It will be more recommended to work with margins or limit chars per line? Cause when user inputs are , . or anothers ASCII wich size is shorter than others ones, the max chars in single line "Changes". So if use margins is most propertly - how the WPF RichTextBox manage margins ?

谢谢!

推荐答案

试图限制每行的字符对我来说就像一场噩梦.你最好去掉 RichTextBox 的默认 ControlTemplate,这样你就只有文本,然后在你的 上设置 MarginRichTextBox 所以文本浮动"在中间:

Trying to limit characters per line sounds like a nightmare to me. You're better off getting rid of the default ControlTemplate for RichTextBox so you just have the text, then setting the Margin on your RichTextBox so the text "floats" in the middle:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ScrollViewer>
        <RichTextBox Margin="30,0">
            <RichTextBox.Template>
                <ControlTemplate TargetType="{x:Type RichTextBox}">
                    <Border x:Name="PART_ContentHost" Margin="2" Background="Transparent" BorderBrush="Transparent"/>
                </ControlTemplate>
            </RichTextBox.Template>
        </RichTextBox>
    </ScrollViewer>
</Grid>

这篇关于如何限制 RichTextBox 中每行最多 83 个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆