Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/WPF: Disable Text-Wrap of RichTextBox

Tags:

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).

Thanks a lot.

Cheers

like image 807
Joseph jun. Melettukunnel Avatar asked Sep 02 '09 14:09

Joseph jun. Melettukunnel


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C full form?

Originally Answered: What is the full form of C ? C - Compiler . C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.


1 Answers

A RichTextBox in WPF is simply an editor for a FlowDocument.
According to MSDN:

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.

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; 

Which will have essentially the same desired effect until you have a line that exceeds the PageWidth.

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.

like image 115
Donut Avatar answered Oct 07 '22 05:10

Donut