locked
Hyperlink formatting issue in RichTextBox RRS feed

  • Question

  • Using VS2010

     

    When trying to add a hyperlink to a richtextbox the resulting display looks like:

     

    WWW.MYDOMAIN.COM/Page <http://WWW.MYDOMAIN.COM/Page>

     

    What I want is just 

     

    WWW.MYDOMAIN.COM/Page 

     

    Using the same source text, this does not occur in any other Rich Text Viewer (MS Word, wordpad, etc)

     

    Thursday, June 2, 2011 3:16 PM

Answers

  • Hi Darren_SE,

    As I said, the RichTextBox will auto detect the urls such as the text start with http://, ftp:// or another one of the 'standard' protocols. The links you've provided is compatible to the Word, but not to the RichTextBox.

    On the other hand, if you want to add the link to the RichTextBox, the following example will help you to resovle your issues:

    Links with arbitrary text in a RichTextBox:
    http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx

    Advanced Text Editor with Ruler:
    http://www.codeproject.com/KB/edit/TextRulerControl.aspx

    You can create your own UserControl and use the Ruler as the second sample[TextRulerControl].

    If you have any questions, please feel free to tell us.

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Thursday, June 16, 2011 1:47 AM
    Tuesday, June 14, 2011 3:03 AM
  • Hi Darren_SE,

    Now I've got your issue.

    When you use Word or WordPad, both of them are compatible to the hperlink format. But the RichTextBox are not.

    The RichTextBox will detect the links automatically. So, when the RichTextBox load the rtf file, it will find the text of the hyperlink and the link url. So, the RichTextBox will show the text with no ambiguity and then it will show the link and attach "<" and ">" to the link and show it as text.

    Another test, you can create a new rft file and input a uri in it and don't create any hyperlink in it. Then, you load it to the RichTextBox, you will find that it shows as I said.

    This is by design and the hyperlink created by Word is not the Rich Text Format for the RichTextBox. If you read the specification of the RichTextFormat, you will find no such specification in it.

    If you have any questions, please feel free to tell us.

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by TylerGG Friday, June 10, 2011 9:31 AM
    • Marked as answer by Neddy Ren Thursday, June 16, 2011 1:47 AM
    Friday, June 10, 2011 9:03 AM

All replies

  • Using VS2010

     

    When trying to add a hyperlink to a richtextbox the resulting display looks like:

     

    WWW.MYDOMAIN.COM/Page <http://WWW.MYDOMAIN.COM/Page>

     

    What I want is just 

     

    WWW.MYDOMAIN.COM/Page 

     

    Using the same source text, this does not occur in any other Rich Text Viewer (MS Word, wordpad, etc)

     


    Hello Darren_SE,

    If you've used the code for the inclusion of 'hyperlink poui place so that you can understand what is wrong?.

    Hello


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/
    Thursday, June 2, 2011 3:48 PM
  • Hi Darren_SE,

    Welcome to the MSDN Forum.

    Here is an sample on how to add the links to the RichTextBox, please see:

    Links with arbitrary text in a RichTextBox:
    http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx

    If you have any concerns regarding this issue, please feel free to let me know.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 6, 2011 5:19 AM
  • I am misstating the issue:

     

    I am not editing anything anywhere, just opening the file and looking at it.

     

    I have an Rich Text File:    MyFile.rtf

    When I open it in Wordpad or Word the hyperlinks display correctly, using the friendly name only:  WWW.MYDOMAIN.COM/Page 

    When I open that very same file in the .NET RichEditBox, they display as:  WWW.MYDOMAIN.COM/Page <http://WWW.MYDOMAIN.COM/Page>

     

    Why would Word and RichEditBox interpret the same file differently?

    Monday, June 6, 2011 8:11 PM
  • I am misstating the issue:

     I am not editing anything anywhere, just opening the file and looking at it.

     I have an Rich Text File:    MyFile.rtf

    When I open it in Wordpad or Word the hyperlinks display correctly, using the friendly name only:  WWW.MYDOMAIN.COM/Page 

    When I open that very same file in the .NET RichEditBox, they display as:  WWW.MYDOMAIN.COM/Page <http://WWW.MYDOMAIN.COM/Page>

     Why would Word and RichEditBox interpret the same file differently?

    Hi Darren_SE,

    I think the rtf file is not a standard RTF format file. If you read the RTF(Rich Text Format) specification, you will find that there are no such element like xml element in the file. And I don't know which version of the .net framework you are using.

    On the other hand, you can create a standard *.rtf as follows:

    Open the Microsoft Office Word(2007 or 2010)
    Enter(don't paste from other places) the quoted words WWW.MYDOMAIN.COM/PAGE 
    Click the File menu and select "Save as"
    In the save file dialog, save the file as *.rtf file.

    Then, open the rtf file with notepad.exe, you will not find any words like <.....>

    Have a look at the newest version of the RTF(Rich Text Format) [1.9]:

    Word 2007: Rich Text Format (RTF) Specification, version 1.9.1
    http://www.microsoft.com/downloads/en/details.aspx?familyid=DD422B8D-FF06-4207-B476-6B5396A18A2B&displaylang=en

    If you have any concerns regarding this issue, please feel free to let me know.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 7, 2011 2:46 AM
  • Nor are there carats within my RTF document.  Which is my question: Why is RichEditBox displaying this when Word is not?

     

    I know how to edit a word document.  As I've said more than once:

     

    Word is displaying the link correctly

    Wordpad is displaying the link correctly.

     

    RichEditBox in .net (all versions that I can target 2.0-4.0) is displaying the <http......> element incorrectly

    I am not asking anyone to verify the syntax of my RTF document.  

    I'm asking why the .net control RichEditBox is exhibiting divergent behavior to the other Microsoft products with regard to displaying the rtf.

     

     

     

    Tuesday, June 7, 2011 7:24 PM
  •  I could only find the TichTextBox. But I can't find the RichEditBox, event can not find the RichEditBox class.

     What is the RichEditBox? Is it a third party control?


    Knowledge will change the destiny.
    Wednesday, June 8, 2011 2:37 AM
  • Hi Darren_SE,

    The RichEditBox is not the control in .Net 2.0-4.0. Now we all use the RichTextBox. You can update your controls to the RichTextBox which is supported by microsoft.

    As I tested above, the RichTextBox will not get the issue and runs which no ambiguity.

    If you have any questions, please feel free to let me know.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 5:59 AM
  • Yes, I misspoke.  I meant to say the RichTextBox.
    Thursday, June 9, 2011 5:52 PM
  •  "As I tested above, the RichTextBox will not get the issue and runs which no ambiguity."


    I don't know what this statement means.

     

    I can see with my own eyes that the RTF file is not being parsed and displayed the same by Word and by RichTextBox in .net.

     

    I'm trying to determine whether there is a bug in RichTextBox, or be are simply using it incorrectly.

    Thursday, June 9, 2011 5:55 PM
  • Here is the proof

     

    The RTF displayed in Wordpad:

     

    The same RTF displayed in RichTextBox

     

    These are actual screen shots

    Thursday, June 9, 2011 6:39 PM
  • Try This:

     

    Here is an RTF File that I have created in Word:

     

    Sample RTF File

     

    Now open this file with a RichTextBox in .net using the following code:

    richTextBox1.LoadFile(@"c:\OahuBound.rtf");

     

    You will see the difference.


    Thursday, June 9, 2011 7:26 PM
  • Hi Darren_SE,

    Now I've got your issue.

    When you use Word or WordPad, both of them are compatible to the hperlink format. But the RichTextBox are not.

    The RichTextBox will detect the links automatically. So, when the RichTextBox load the rtf file, it will find the text of the hyperlink and the link url. So, the RichTextBox will show the text with no ambiguity and then it will show the link and attach "<" and ">" to the link and show it as text.

    Another test, you can create a new rft file and input a uri in it and don't create any hyperlink in it. Then, you load it to the RichTextBox, you will find that it shows as I said.

    This is by design and the hyperlink created by Word is not the Rich Text Format for the RichTextBox. If you read the specification of the RichTextFormat, you will find no such specification in it.

    If you have any questions, please feel free to tell us.

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by TylerGG Friday, June 10, 2011 9:31 AM
    • Marked as answer by Neddy Ren Thursday, June 16, 2011 1:47 AM
    Friday, June 10, 2011 9:03 AM
  • If you open the file up and look at its raw form, the hyperlink is defined by the following markup.

     

     {\field{\*\fldinst {
    \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16660646  HYPERLINK "http://OahuBound.com" }{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16660646 {\*\datafield
    00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b4400000068007400740070003a002f002f006f0061006800750062006f0075006e0064002e0063006f006d002f000000795881f43b1d7f48af2c825dc485276300000000a5ab000000}}}{\fldrslt {\rtlch\fcs1
    \af0 \ltrch\fcs0 \cs15\ul\cf17\insrsid16660646\charrsid16660646 OahuBound.com}}}

     

    This was created by WORD.  Is this markup code not RichText?

    Friday, June 10, 2011 3:16 PM
  • If you open the file up and look at its raw form, the hyperlink is defined by the following markup.

      {\field{\*\fldinst {
    \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16660646  HYPERLINK "http://OahuBound.com" }{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16660646 {\*\datafield
    00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b4400000068007400740070003a002f002f006f0061006800750062006f0075006e0064002e0063006f006d002f000000795881f43b1d7f48af2c825dc485276300000000a5ab000000}}}{\fldrslt {\rtlch\fcs1
    \af0 \ltrch\fcs0 \cs15\ul\cf17\insrsid16660646\charrsid16660646 OahuBound.com}}}

     This was created by WORD.  Is this markup code not RichText?


    You are right. Such code was created by Word. But the code format are not in Rich Text Format in the RichTextBox.

    You can have a look at the specification of the RichTextformat:

    Rich Text Format (RTF) Specification, version 1.9.1:
    http://www.microsoft.com/downloads/en/details.aspx?familyid=DD422B8D-FF06-4207-B476-6B5396A18A2B&displaylang=en 

    If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.



    • Edited by Neddy Ren Tuesday, June 14, 2011 1:34 AM
    Monday, June 13, 2011 6:21 AM
  • Have you actually looked at the RTF spec that you are linking?

    Can you provide me with one example of a tag from the code I posted that isn't in this specification?

    Monday, June 13, 2011 7:56 PM
  • Hi Darren_SE,

    As I said, the RichTextBox will auto detect the urls such as the text start with http://, ftp:// or another one of the 'standard' protocols. The links you've provided is compatible to the Word, but not to the RichTextBox.

    On the other hand, if you want to add the link to the RichTextBox, the following example will help you to resovle your issues:

    Links with arbitrary text in a RichTextBox:
    http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx

    Advanced Text Editor with Ruler:
    http://www.codeproject.com/KB/edit/TextRulerControl.aspx

    You can create your own UserControl and use the Ruler as the second sample[TextRulerControl].

    If you have any questions, please feel free to tell us.

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Thursday, June 16, 2011 1:47 AM
    Tuesday, June 14, 2011 3:03 AM