Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6041403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:39:24+00:00 2026-05-23T06:39:24+00:00

I need to suppress some linebreaks in a RichTextBox. For example, consider d6+ .

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:39:24+00:00Added an answer on May 23, 2026 at 6:39 am

    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 Handle property of the RichTextBox to 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_CLASSIFY and others.

    • winuser.h
    • richedit.h

    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)

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace q6359774
    {
        class MyRichTextBox : RichTextBox
        {
            const int EM_SETWORDBREAKPROC = 0x00D0;
            const int EM_GETWORDBREAKPROC = 0x00D1;
    
            protected override void OnHandleCreated(EventArgs e)
            {
                base.OnHandleCreated(e);
                this.Text = "abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz";
                NewMethod();
            }
    
            unsafe private void NewMethod()
            {
                if (!this.DesignMode)
                    SendMessage(this.Handle, EM_SETWORDBREAKPROC, IntPtr.Zero, Marshal.GetFunctionPointerForDelegate(new EditWordBreakProc(MyEditWordBreakProc)));
            }
    
            [DllImport("User32.DLL")]
            public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
    
            unsafe delegate int EditWordBreakProc(char* lpch, int ichCurrent, int cch, int code);
    
            unsafe int MyEditWordBreakProc(char* lpch, int ichCurrent, int cch, int code)
            {
                const int WB_ISDELIMITER = 2;
                const int WB_CLASSIFY = 3;
                if (code == WB_ISDELIMITER)
                {
                    char ch = *lpch;
                    return ch == '-' ? 0 : 1;
                }
                else if (code == WB_CLASSIFY)
                {
                    char ch = *lpch;
                    var vResult = Char.GetUnicodeCategory(ch);
                    return (int)vResult;
                }
                else
                {
                    var lpch2 = lpch;
                    // in this case, we must find the begining of a word:
                    for (int it = ichCurrent; it < cch; it++)
                    {
                        char ch = *lpch2;
                        if (it + 1 < cch && lpch2[0] == '-' && lpch2[1] != '-')
                            return it;
                        if (lpch2[0] == '\0')
                            return 0;
                        lpch2++;
                    }
                }
    
                return 0;
            }
        }
    }
    

    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.

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace q6359774
    {
        class MyRichTextBox : RichTextBox
        {
            const int EM_SETWORDBREAKPROC = 0x00D0;
            const int EM_GETWORDBREAKPROC = 0x00D1;
    
            protected override void OnHandleCreated(EventArgs e)
            {
                base.OnHandleCreated(e);
                this.Text = "abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz";
                if (!this.DesignMode)
                    SendMessage(this.Handle, EM_SETWORDBREAKPROC, IntPtr.Zero, Marshal.GetFunctionPointerForDelegate(new EditWordBreakProc(MyEditWordBreakProc)));
            }
    
            [DllImport("User32.DLL")]
            public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
    
            delegate int EditWordBreakProc(string lpch, int ichCurrent, int cch, int code);
    
            int MyEditWordBreakProc(string lpch, int ichCurrent, int cch, int code)
            {
                const int WB_ISDELIMITER = 2;
                const int WB_CLASSIFY = 3;
                if (code == WB_ISDELIMITER)
                {
                    if (lpch.Length == 0 || lpch == null) return 0;
                    char ch = lpch[ichCurrent];
                    return ch == '-' ? 0 : 1;
                }
                else if (code == WB_CLASSIFY)
                {
                    if (lpch.Length == 0 || lpch == null) return 0;
                    char ch = lpch[ichCurrent];
                    var vResult = Char.GetUnicodeCategory(ch);
                    return (int)vResult;
                }
                else
                {
                    if (lpch.Length == 0 || lpch == null) return 0;
                    for (int it = ichCurrent; it < lpch.Length; it++)
                    {
                        char ch = lpch[it];
                        if (ch != '-') return it;
                    }
                }
    
                return 0;
            }
        }
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to insert selected text on the page into textarea. There must be some
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I need to parse some HTML files, however, they are not well-formed and PHP
I need to suppress a specfic compiler warning in C#. Now I can do
Need to call a filter function on some options based on a radio selected
Need some help to solve this. I have a gridview and inside the gridview
I need to suppress a label and image if certain data is encountered. Is
I have some JSF code that currently works (as shown below), and I need
We have numerous python classes that do not seem to need __init__ , initialising
Don't flame but I'm still a python newbie. I need to suppress the carriage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.