0

I have a really big problem with my vb.net Project using framwork 4.7 (so RICHEDIT50W should be used by default as suggested here).

Perhaps I should tell, I am coding with VB.net just half a year with using VS2022. Until the year 2000 I have programmed with VB6. All the years between I had no free time for coding.

And I am not sure, if this article is describing my problem - my english is not as good, since schooltime is long ago. Also I have searched everywhere, without finding a solution for that problem.

Problem: I create a test rtf-document with four regular links. This documant works fine, each click onto one of this links is calling the linkclicked-routine of the rtfbox. Then I insert a hidden hyperlink (means a link with a linkURL and another LinkDescription like "Click here" or some else) between the existing link 2 and 3

Dim linkURL as string = "https://welt.de"
Dim LinkDescription as string = "Ckick here"
Dim rtflink As String = "{\rtf1\ansi{\fonttbl{\f0\fcharset0 " & fontName & ";}}<" & "{\field{\*\fldinst{HYPERLINK " & linkURL & """}}" & "{\fldrslt{" & linkDescription & "\ul0\cf0}}}>}"
rtfbox.SelectedRtf = rtflink

This link is displayed correct in the rtfbox then. But if I move the caret onto this link, the rtfbox.selectionstart get unecpected values and the links 4 and 5 wont call the linkclicked-sub anymore. rtfbox.selectionstart shows correkt numbers until the caret is over the first char of the displayed link description.

Same problem occurs, if i create a new document in MS-Word, and reproduce this procedure. I build four links in that Word document, save this as rtf-format and open the saved rtf in my rtfbox. Works well with all four links in Word and I can open each link by ctrl+click onto one of the links.

But if I insert in MS-Word then a link with a hidden Link (other linkdescription than the linkURL) between link 2 and link 3, save this document again as rtf-format and open this Word-created document in my rtfbox, i have exactly same problen as described. Link 3 and link 4 wont call linkclicked anymore and rtfbox.selectionstart tells irregular values if the caret is place over the hidden link.

In MS-Word all five links are working fine if I ctrl-click onto one of the five links.

The problem only exists in the rtfbox, as it seems to me.

I found out, if I place either a non existing url into the linkdescription like "http://www.rest.de" or a normal text like "Click here" this problem occures. A existing URL in the description makes no problems.

Could it be possible, that the rtf-interpreter of the net-framework has a build in problem? To me it seems, the interpreter tests if in the desctiption field a regular and existing link is placed instead testing the linkURL as should be expectable .

Can someone help me to get hidden hyperlinks working in the rtfbox perhaps?

EDIT: Hi Jimi, thanks for your reply. Have not known that. In most forums an editing of existing posts is not wished.

Here a small RTF-Source-Code what explains my problem.

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1031{\fonttbl{\f0\fnil\fcharset0 Rockwell Extra Bold;}{\f1\fnil Consolas;}} {\colortbl ;\red0\green0\blue255;\red0\green0\blue0;} {\*\generator Riched20 10.0.19041}{\*\mmathPr\mdispDef1\mwrapIndent1440 }\viewkind4\uc1 \pard {\cf1\f0\fs24{\field{\*\fldinst{HYPERLINK "https://www.example.com"}}{\fldrslt{\ul\cf1 Click here}}}}\cf1\f0\fs24 \cf2\f1\par \f0 aaa bbb\cf1\par {{\field{\*\fldinst{HYPERLINK "https://www.example.com"}}{\fldrslt{\ul\cf1 Click here}}}}\cf2\f1\fs24\par \f0 aaa bbb\cf1\par {{\field{\*\fldinst{HYPERLINK "https://www.example.com"}}{\fldrslt{\ul\cf1 Click here}}}}\cf2\f1\fs24\par \f0 aaa bbb\cf1\par {{\field{\*\fldinst{HYPERLINK "https://www.example.com"}}{\fldrslt{\ul\cf1 Click here}}}}\cf2\f1\fs24\par \f0 aaa bbb\cf1\par {{\field{\*\fldinst{HYPERLINK "https://www.example.com"}}{\fldrslt{\ul\cf1 Click here}}}}\cf2\f1\fs24\par \f0 aaa bbb\par \cf1\par \par }

If you copy that code in an texteditor and saving this with a .RTF-ending, you should see, what is my problem. When open this .rtf in MS-Word or Wordpad each link works fine. But if opening this rtf in a richtextbox, only the first two links are working and calling the link_clicked handler. The last three does nothing. If showing rtfbox.selecionstart with caret on row 0 col 0, it has 0. When moving the caret one char to the right (row 0 col 1), rtfbox.selectionstart has the value 36. That nags me, cause I need that hidden links in my project. Kind regards

Edit 2: Changing the quotes covering the url into doublequotes makes no difference - same problem as described.

The only way to get hidden links working in the richtextbox is to write a existing and correct formatted url into the "field result" (fldrstl). This if "rtfbox.detecturls = true" as well if "rtfbox.detecturls = false". To me it seems, there is a bug in the rtf-interpreter. The interpreter is testing the "field result" in same way as the field "hyperlink". What maks no sence in my oppinion.

Dideldum
  • 1
  • 2
  • Your composited string doesn't look correct. The link's URL must be included in double-quotes. Using an interpolated string may ease the composition -- As a note, MS Word doesn't use the 50W version, it uses the 60W version (and its own stuff). Also note that the .NET RichTextBox, unfortunately, is missing all advanced typographic features. You might want to utilize Wordpad as sidekick instead, this one uses 50W (in Windows 7 / 10) – Jimi Aug 31 '23 at 21:40
  • Hi Jimi, thanks for your Hints. I made a test-RTF meanwhile: – Dideldum Sep 01 '23 at 00:03
  • {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1031{\fonttbl{\f0\fnil\fcharset0 Rockwell Extra Bold;}{\f1\fnil Consolas;}{\f2\fnil\fcharset0 Consolas;}} {\colortbl ;\red0\green0\blue255;\red0\green0\blue0;} {\*\generator Riched20 10.0.19041}{\*\mmathPr\mdispDef1\mwrapIndent1440 }\viewkind4\uc1 \pard\cf1\f0\fs24 {\field{\*\fldinst HYPERLINK "https://www.example.com"}{\fldrslt Hier klicken}} \cf2\f1\par \f0 aaa bbb\cf1\par {\field{\*\fldinst HYPERLINK "https://www.example.com"}{\fldrslt Hier klicken}}\cf2\f1\fs24\par \f0 aaa bbb\cf1\par ... – Dideldum Sep 01 '23 at 00:13
  • {\field{\*\fldinst HYPERLINK "https://www.example.com"}{\fldrslt Hier klicken}}\cf2\f1\fs24\par \f0 aaa bbb\cf1\par {\field{\*\fldinst HYPERLINK "https://www.example.com"}{\fldrslt Hier klicken}}\cf2\f1\par \f0 aaa bbb\cf1\par {\field{\*\fldinst HYPERLINK "https://www.example.com"}{\fldrslt Hier klicken}}\cf2\f1\par \f0 aaa bbb\cf1\par – Dideldum Sep 01 '23 at 00:14
  • If saving this rtfcode as rtf-format, and open that rtf-document in Word, all Links works fine. But when loading the same rtf-document into the RichTextBox, only the first two links sends a link_clicked event. The following three links are doing nothing. And if moving the caret from pos 0 to 1, the rtfbox.selectionstart is jumping from 0 to 36 by that. Is there a possibility to get that working in the richtextboxes perhaps? Unfortunately I absolutely should have the linkurls im my project with other link-descriptions. – Dideldum Sep 01 '23 at 00:14
  • I suspect more and more an error in the interpreter of the rich text box – Dideldum Sep 01 '23 at 00:15
  • In Wordpad the loaded rtf-document works also. – Dideldum Sep 01 '23 at 00:17
  • But unfortunatels I don't understand the meaning of "You might want to utilize Wordpad as sidekick instead, this one uses 50W (in Windows 7 / 10)" It's a must to have the rtfbox as preview-viewer in my program. There are 221 different rtf-documents as Help-Archieve each with some links inside. The complete Help-function of my program is build this way. Additional the program is build to can quick edit some filetypes -also rtf-format. The User can open all the files with one mouseclick in an external editor. But he must be able to make small edits directly in the program. – Dideldum Sep 01 '23 at 00:23
  • Please, don't post any code (or RTF parts in this case) in comments. [Edit](https://stackoverflow.com/posts/77016990/edit) your question and post any update there. Also, make sure you always post complete snippets of code or otherwise (something that can be immediately copied and pasted elsewhere or testing), your RTF is incomplete -- As noted, MS Word use a different version of the RTF composer. I suggested to use Wordpad instead. Also note that these are applications. When you paste something in the app, it's subject to validation and formatting. Your RTF's links are missing double-quotes – Jimi Sep 01 '23 at 11:19

0 Answers0