I need to suppress some linebreaks in a RichTextBox.
For example, consider d6+. There must not be a line break between 6 and +. Basically I’m looking for something like <nobr> in HTML.
So far, I’ve messed around with inserting \u+FEFF etc (which worked on some machines, but some showed vertical lines, maybe a font problem although windows standard font). I also tried to manipulate the rtf directly, i.e. box.rtf = ... with putting some \zwnbo in there, but I never seem to get it right.
Help much appreciated.
Yes, you can use all of the RichText API with your RichTextBox control.
You may be interested take a look at the following sites:
http://www.pinvoke.net/default.aspx/user32.sendmessage – how to send messages to windows using p/invoke.
You can use the
Handleproperty of theRichTextBoxto get the window handle of that control, and then send messages to it.Also look at these include files shiped with SDK from Microsoft, thaty are not going to be used directly in C#, but these files constains all constants you may have to use, such as
WB_ISDELIMITER,WB_CLASSIFYand others.In the following example I
demonstrate how to use the APIs
provided.
EDIT:
This new sample has code marked as unsafe, but it is better because it does not suffer from the problem of single character string, since I can have a
char*parameter and manipulate it. The old sample follows this one:This is C# code, not C++… to compile it you will have to go to project options and mark the check-box to allow unsafe code to run.
Right click the project -> Properties (Alt+Enter) -> Build -> General -> Allow unsafe code (must be checked)
Old Sample Code
The sample consists of a class that inherits from RichTextBox and places a custom handler using
EM_SETWORDBREAKPROC. This class will only break lines exactly when over ‘-‘ character. Not before, nor after.It is just a draft, so you may have to further improve it, so you can achieve your goals.
Place the control in a windows form, and run.
Resize the window and see if this is what you want to do!
You will have to make the seeking of word boundaries… I didn’t manage to make it work yet.