RTF / RichTextBox - How to get table cell borders invisible – etc.?


  • Hello,

    Q1: I’m generating RTF coded documents from some database queries. The 1. problem now is that the RichTextBox control shows border lines for all cells. At least these control words from the rtf 1.9 spec don’t seem to have any impact:

    \brdrnil = No border specified

    Both the Richtexbox and WordPad show the cells while Word2010 knows to hide them as well as OO Writer.

    Is there a way to get rid of them with rtf control words in RTbox?  If not, is there perhaps an EM_ message to set the border color to match the background color in the Rtbox suign an API call?

    I’ve been using this for testing:

    {\f0\fswiss Arial;}
    \pard\intbl\ql {\fs22 tablecell1}\cell
    \pard\intbl\ql {\fs22\b tablecell2}\cell
    \pard\intbl\qc {\fs24\i tablecell3}\cell
    \pard\intbl\qr {\fs26\b\i tablecell4}\cell

    Q2. For some reason Word inserts quite a few \tab:s into the first cell breaking the alignment. Why is that and how to get rid of that habbit?

    I'm using VS2010 pro and C#.

    FYI: I have used a couple of days to find an answer to Q1 with no luck, wasting precious working time by reading probably a hundred discussions regarding this particular issue. There is a discussions in social.msdn , (for which I'm not allowed to post a link now ) which may have presented an answer, but the link to the actual solution isn't working any more. I have a feeling that it may have suggested the using of the old VB6 RTb control but that would have been a nogo.



    Friday, March 22, 2013 7:45 PM

All replies

  • Hi robopoulos,

    Thank you for the detail information. I did reproduce this issue on my side.

    I did some search on this topic and I'm not quite sure why MS words doesn't display cell border since rtf specification include table control,see

    This topic need word related technology and I'm afraid that I'm able to help you.

    I had invoked other engineers into this issue.

    Best Regards,

    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 26, 2013 9:21 AM
  • Hi robopoulos,

    I experimented with the RTF you provided above and observed that if I remove the space and newline characters after \trrh320 and before the actual content in the table, the extra spaces were not displayed in Word.  I'm not sure why those extra spaces are getting interpreted as part of the content of the first cell there, but the Word team might be able to investigate that further in a support case if you need to understand it better. 

    Unfortunately, it seems there is no way to prevent these border lines using the RichTextBox.  The control is simply limited in the scope of its functionality.  You could automate Word to provide a fully featured interface as one option, or there are also third party controls with extended functionality as well.

    Thank you!

    Jon Burchel

    Tuesday, March 26, 2013 9:44 PM
  • There is no need for third party controls or Word automation. The major issue is that even VS2010 SDK 7.1 uses an ancient version on Richtextbox control. The second problem is the MSs lack of proper documentation for RichtextBox control, at least with C#. Considering the amount of posts in the net regarding problems with the Richtextbox it would be a decent thing from MS’s part to deliver proper documentation for their product. The total amount of wasted hours and resources must be huge.

    Problems started to unfold after I explicitly loaded Richtextbox version 6 (msftedit.dll) with LoadLibrary. This also fixed some other issues, like issues with cell height and not accepting cell border color. However, so far I have not been able to hide the cell border lines in a proper manner while my Richtextbox Print Preview does the hiding automatically after the loading of ver. 6 of Richtextbox. So there is a way to do this. 

    I'm now temporarily achieving the hiding for the Richtextbox I use for viewing the db queries by setting each and every border lines' line width to 1 twip and then setting their color to same as the background color. (The line needs to have a width for the color to work). I naturally skip this obviously unnecessary phase when saving to file for Word or Open Office Writer:


    My Richtextbox is actually a derived class of Richtextbox with some extended properties which I get by using SendMessage.  The PARAFORMAT2 struct used with EM_SETPARAFORMAT has many settings for the Richtextbox including border lines. However, while for instance adjusting of the line spacing works OK, I haven’t been able to get any of the settings for border lines to work. I would appreciate information regarding this approach to hide the lines. I also haven’t been able to find any documentation regarding the SendMessage return value with EM_SETPARAFORMAT/PARAFORMAT2 which would be necessary when trying to solve the problem.  After that I would be off the hook from technical problems and could continue the actual work.



    PS. Thanks for the /n hint with Word.

    Thursday, March 28, 2013 10:03 AM