Link to home
Start Free TrialLog in
Avatar of macarone
macarone

asked on

Richtextbox: Hyperlink embedded in text problem

Hello,
I have a problem with a richtextbox control (programming environment: VB.NET + VS2500).
Here is the scenario:
I have 2 different applications, each containing a winform with a richtextbox control.
In one application if I copy some text that contains an embedded hyperlink from - let's say - a web page, when I paste such text in the richtextbox the hyperlink will remain embedded in the text (just like in the original web page).
In the other application if I paste the same text (copied from the web page) the hyperlink is no longer embedded in the text. Instead it appears next to the text, like in this example: my_text_with_embeeded_link<http://www.mysite.com>

Both RTF controls have the exact same settings (properties), so I really don't understand what's going on here.
Please help.
Thank you,
Mac
Avatar of srinivasbn
srinivasbn
Flag of United States of America image

Hi Please check the property DetectUrls. If this is true then it will automatically finds the urls in the text.


Srinivas.
Avatar of macarone
macarone

ASKER

Hi Srinivas,

the DetectUrls = True for both RTF controls.
The problem is not recognizing URLs but being able to "embed" a given URL in a word/sentence.

Any other ideas?
Thank you
I think what you are saying is that it needs to understand the html like Mylink will be caption and href will be some http url. In that case I suppose you need to use html editor typr control rathr than richtextbox or control which understands the html atgs.
manlimnag:

I would agree with you on that, but - as I mentioned - in one application (a COM addin for Microsoft Office) the "html like" link works fine. However it does not work in the other app (a standalone .NET application).

How is it possible that it works just fine in one app and not in the other one?
That is the question.
I am not sure but it may be feature of MS Office and not a feature of .Net
More clarification Is it renedering properly and navigtion is not working or renderring is the problem?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Imagine you have a word document or an HTML page with a word (or a sentence) that contains an hyperlink. For example the word "my site" that contains an hyperlink like "http://www.mysite.com"....you don't see the hyperlink but if you move your mouse over the "my site" text you see that you can click on it and follow its "embedded" hyperlink.

Imagine now that you select and copy the "my site" text and paste it an RTF box embedded in two different applications.
Now, in one case (the COM addin) the RTF control will display what you just pasted as it appears in the word document (or web page), meaning you see only the "my site" text, but if you move your mouse on it you can see there is an hyperlink behind it.
In the other case instead, you'll see the text "my site" and, next to it, the hyperlink between these two symboles <>. Ultimately it would look like this:   "mysite<http://www.mysite.com>"

I just don't understand why in one case the RTF behaves like word (or browser) while in the second case it splits the hyperlink from its text....clearly, if you configure detectURLs=true then the RTF box will "activate" the hyperlink <http://www.mysite.com>.

The question is: why is this happening and how can I have the RTF box to behave properly in both cases (= the hyperlink is hidden behind the text like in word or browser).

Hope this can help.
Mac





Its the hosting environment that's causing this rather than RTF itself. May the difference is in copy and paster operation when it happens within word and when it happens from word to outside world.
Hi Mac,

Are you sure you are using both RTF components. What i understood with your description you might add the CustomControl (COM addin) which may have the feature of copying the entire text just like in word. But the .net RTF can't copy the hidden text.

Please verify once your components.


Srinvias.
Maybe CodeCruiser you are right. But I would not pinpoint the copy-paste operation.
Instead, is it possible that the RTF control behaves differently within a VB.NET COM Addin for MS Office vs. a regular standalone VB.NET application?

I made another test with same results. Let me explain:

1) go to the COM Addin application where the RTF control displays the hyperlinks correctly (see my previous comments)

2) copy/paste some text with an embedded hyperlink and make sure the RTF control displays the hyperlink correctly (=embedded in text)

3) memorize in a string the .rtf content of the RTF control using:
Dim myRTFcontrol_content As String = My_RTF_Control.rtf

4) save and load the same .rtf in the RTF control used in the other application (making sure that the .rtf text loaded is EXACTLY the same in both cases).

RESULT: the RTF control in the second application (.NET standalone application) shows the same error, therefore displaying the same .rtf in a different way.
Pretty weird! unless the same .NET RTF control in two different environments behaves in two different ways. If so, any suggestion on how to prevent this ?

Thank you.
Hmm. That's weired. Is using the HTML control an option?
CodeCruiser:
I agree, it's very weird...the same control loading the same .rtf string will display it in two different ways (A) in a COM addin for MS Office  vs. (B) a standard standalone .exe application (both created with the same VB.NET technology)!
Unfortunately using the HTML control is not an option at this point although I recognize it is a valid alternative in other scenarios different from mine.
Any other ideas?
Cant think of any other way to be honest.
does not solve the problem but provides a good alternative approach to prevent the problem from happening in the first place.