Re: C Sharp RichEditBox HyperLinks

From: Brett Verhagen (kalluminati2001_at_yahoo.com)
Date: 01/08/04


Date: 8 Jan 2004 01:07:24 -0800

Ok I'll try to explain this the best I can. I am using visual studios
net. I have a C Sharp form with a RichTextEditBox. In the text field i
tell it to say www.google.com. So the code goes something like this

        richTextBox1.SelectedText = "www.google.com";

Ok when I do that the text is underlined and if the user clicks on the
text this event will be called

        private void richTextBox1_LinkClicked(object sender,
                System.Windows.Forms.LinkClickedEventArgs e)

Which is perfect. The only problem is I do not want the text to say
google.com or any other address for that matter. Now in word I can
create files that that have the extension rtf. I also found code that
will load a rtf into my RichTextBox. It will load colors, text, fonts,
and hyperlinks.

Now using word I can take any letters or string of letters and
instruct the computer to bring up any web address I like whenever the
letters are clicked. regardless of what the letters say.

The problem is when I do that and try to load this rtf document into
my RichTextBox it does not work. The text I selected is underlined and
appears to be a link but when I click the text nothing happens. The
LinkClicked event is supposed to run. I think that maybe by clicking
the text another event is called.

> > In the text field I display something like "www.google.com" and
> > when the user clicks it, my code is run.
>
> What "text field"? In the RTF document?

I am talking about in the RichTextBox in the text field. In C Sharp I
run code similar to this :

richTextBox1.SelectedText = "www.google.com";

> Your code runs when loaded
> into the RTF Edit control? If so, the solution may be easy. Use
> Word to edit the link (Word allows you to specify both what appears
> on the document and what the link text is). Then use a plain text
> editor to see what Word did with the RTF. I tried it, and got this
> (extracted from the entire document):
>

Yeah I have been able to do that with word. It works exactly how I
want it to in word. Unfortunatly when I load the "working" rtf
document onto my form. When I load the document into my RichTextBox
The link does not act the same. The text is underlined and appears to
be a link. But when the text www.google.com is clicked this event runs

        private void richTextBox1_LinkClicked(object sender,
                System.Windows.Forms.LinkClickedEventArgs e)

when I load the rtf document and the hyperlink is clicked this event
does not run. I have only been able to get that event to run when the
text is that of a web address. Maybe another event is called, if i
could figure out which event gets called that would work.

> I wrote an RTF "notepad"-alike a while back that had active links
> (not to webpages, but to various commands). What I did was catch
> user double-clicks, use that to get the click point, work both
> ways (forwards and backwords) to find the word, and once I had that,
> it was just a matter of dispatching on the clicked word.

I am probably going to have to do that. Of course the coding and the
ensuing errors sounds high.

Thanks
Brett



Relevant Pages

  • Re: Rich Text parsing with RichTextBox
    ... > color from the RTF strings. ... > RichTextBox doesn't seem to be able to understand my RTF. ... > rich text control. ... > SelectionColor still returns Color.Empty. ...
    (microsoft.public.dotnet.framework)
  • RE: Initializing a RichTextBox
    ... The Rtf property of RichTextBox gets or sets the text of the RichTextBox ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.windowsforms)
  • RE: Effective coloring in RichTextBox
    ... Making RTF code by hand appeared on my mind, but that's what I didnt want to ... This control is a superset of the RichTextBox control. ... RichTextBox control with the ability to capture, recognize, and display ink. ... manually and avoid the calling of SelectionColor ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How to load rtf in richtextbox with header and footer
    ... RTF codes that specify a header and footer to work inside a RichTextBox? ... That _does_ operate basically on a page level, and if you embed it into your own control that could produce the visual results you're looking for. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RichTextBox requires tons of memory for text
    ... This is not a .NET issue, but the normal behavior of the RichTextBox ... the memory is taken from the unmanaged heap. ... Just load your ... > Software Engineer ...
    (microsoft.public.dotnet.framework)