How to handle click on URL in a RichTectBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to have a URL in my RichTextBox so when user click on the URL,
it will open up a browser with in the selected address.

Thanks

Al
 
1. Set the rtb's DetectUrls property to true
2. Handle the rtb's LinkedClicked event something like this:

Private Sub Rtb_LinkClicked(ByVal sender As Object, ByVal e As
Windows.Forms.LinkClickedEventArgs) Handles Rtb.LinkClicked
Diagnostics.Process.Start(e.LinkText) ' launch the link
Return
End Sub
 
Its Ironic that you asked this question now, as two days ago I wrote a
program which done just that as part of the application

Here's a direct Copy of my code:
---------------------------------

#Region "Rich Text Box LinkClicked Event()"

Private Sub rtbInfo_LinkClicked(ByVal sender As Object, ByVal e As
System.Windows.Forms.LinkClickedEventArgs) Handles rtbInfo.LinkClicked
System.Diagnostics.Process.Start(e.LinkText)
End Sub

#End Region

---------------------------

If you noticed in the first answer that was given the user used 'RETURN'
when there are no 'RETURNS' from 'Subs' only 'Functions'

Herfried is linking people to his website again I see when he could either
give a direct link to the others code or type in the code itself. I suppose
he wants hits to his website.

Anyway, I hope this has helped

Crouchie1998
BA (HONS) MCP MCSE
 
Crouchie,

Crouchie1998 said:
If you noticed in the first answer that was given the user used 'RETURN'
when there are no 'RETURNS' from 'Subs' only 'Functions'

'Return' will work with 'Sub' procedures too, however, it doesn't make sense
in the sample posted in AMercer's reply.
Herfried is linking people to his website again I see when he could either
give a direct link to the others code or type in the code itself.

I am lazy... :-).
 
If you noticed in the first answer that was given the user used 'RETURN'
'Return' will work with 'Sub' procedures too, however, it doesn't make sense
in the sample posted in AMercer's reply.

MS online help says:

"Use the Return statement whenever your logic permits it. For more
information, see Return Statement. The compiler can optimize the code better
than if you use Exit Function, Exit Property, or Exit Sub, or allow the End
Function, End Get, End Set, or End Sub statement to generate a return."

On the other hand, MS online help also says:

"A Return statement, returns execution to the expression that invoked the
method. If the method is a subroutine, the statement is equivalent to an Exit
Sub statement and no expression may be supplied."

Conflicting guidance ... what to do. Well, it seemed to me that guidance
about using 'exit xxx' and 'end xxx' was older, and that vb .net gained a
little in performance by functionally equivalent uses of return. So, I've
developed the habit of putting return statements at the bottom of subs. Does
this really not make sense? What does MS say? If there is an advantage, I
want to leave the returns in. If there is a loss or equality, I want to
remove them.
 
AMercer said:
MS online help says:

"Use the Return statement whenever your logic permits it. For more
information, see Return Statement. The compiler can optimize the code
better
than if you use Exit Function, Exit Property, or Exit Sub, or allow the
End
Function, End Get, End Set, or End Sub statement to generate a return."

On the other hand, MS online help also says:

"A Return statement, returns execution to the expression that invoked the
method. If the method is a subroutine, the statement is equivalent to an
Exit
Sub statement and no expression may be supplied."

Conflicting guidance ... what to do. Well, it seemed to me that guidance
about using 'exit xxx' and 'end xxx' was older, and that vb .net gained a
little in performance by functionally equivalent uses of return. So, I've
developed the habit of putting return statements at the bottom of subs.
Does
this really not make sense? What does MS say? If there is an advantage

Using 'Return' doesn't have an advantage over using 'Exit Sub'. It will
generate the same IL. In your sample 'Return' was not necessary because a
method will return automatically if it doesn't contain more code to be
executed.

Consider the code below:

\\\
Public Sub A()
Beep()
Return
End Sub

Public Sub B()
Beep()
Exit Sub
End Sub

Public Sub C()
Beep()
End Sub
///

This IL will be emitted by the compiler:

\\\
..method public instance void A() cil managed
{
// Codegröße 12 (0xc)
.maxstack 8
IL_0000: nop
IL_0001: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0006: nop
IL_0007: nop
IL_0008: br.s IL_000a
IL_000a: nop
IL_000b: ret
} // end of method Form1::A

..method public instance void B() cil managed
{
// Codegröße 12 (0xc)
.maxstack 8
IL_0000: nop
IL_0001: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0006: nop
IL_0007: nop
IL_0008: br.s IL_000a
IL_000a: nop
IL_000b: ret
} // end of method Form1::B

..method public instance void C() cil managed
{
// Codegröße 9 (0x9)
.maxstack 8
IL_0000: nop
IL_0001: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0006: nop
IL_0007: nop
IL_0008: ret
} // end of method Form1::C
///

As you can see, using 'Return' and 'Exit Sub' doesn't make a difference, but
using none of them in our particular case will generate the shortest IL.
 
Herfried,

This sounds for me from the beginning of the Cobol Time.

In the beginning there were buggy Cobol compilers who acts a little bit as
assembler and the code was mostly written as that.

There had to be a return (Assembler Branch Unconditional to the next address
after the Caller(stack or register)) or it would go wrong. For me it looks
if some people think that this wrong behaviour still exist.

Maybe you knew this already, on the other hand in my opinion nothing wrong
with this message.

Cor
 
You aren't returning anything in a sub. Return is used for return values;
things (functions) that return a result

Crouchie1998
BA (HONS) MCP MCSE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top