C#/ WPF:RichTextBox中的禁用文本换行 [英] C#/WPF: Disable Text-Wrap of RichTextBox

查看:1716
本文介绍了C#/ WPF:RichTextBox中的禁用文本换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我可以禁用的文字环绕一个的RichTextBox
例如如果我不适合在窗口大字符串时,的RichTextBox 地方不能显示新行的字符串的一部分。我想禁用(并使其可见只有通过使用滚动条)。

Does anyone know how I can disable the text wrapping of a RichTextBox? E.g. if I have a large string which doesn't fit in the window, the RichTextBox places the part of the string which can't be shown of a new line. I want to disable that (and make it visible only by using the Scrollbar).

非常感谢。

干杯

推荐答案

一个的 的RichTextBox 在WPF只是一个编辑< A HREF =htt​​p://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.aspx> 的FlowDocument

根据 MSDN

文本始终包裹在的RichTextBox 。如果
你不希望文字换行然后设置
的的页宽的FlowDocument

的RichTextBox 的宽度。然而,一旦网页
宽度达到文本仍换行。

Text always wraps in a RichTextBox. If you do not want text to wrap then set the PageWidth on the FlowDocument to be larger than the width of the RichTextBox. However, once the page width is reached the text still wraps.

所以,虽然没有办法给你明确禁用的的RichTextBox ,你可以做这样的事情的文字环绕:

So, while there's no way for you to explicitly disable the word-wrapping of a RichTextBox, you can do something like this:

richTextBox1.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
richTextBox1.Document.PageWidth = 1000;



直到你有超过了页宽

注意(截至2015年7月的):VS2015 RC允许换行= FALSE 作为OP似乎想要精确工作。我相信,早期版本的Visual Studio中也做了。

Note (as of July 2015): VS2015 RC allows wordwrap = false to work precisely as OP seems to desire. I believe earlier versions of Visual Studio did also.

这篇关于C#/ WPF:RichTextBox中的禁用文本换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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