2009-07-21 16 views
1

Je souhaite définir une ligne de texte dans la zone de texte enrichi de vb.net. Comme par exemple: Je veux vous connaîtreRichTextBox

Le mot vouloir, je veux définir un mot de liaison.

Puis-je faire cela? Si possible, aidez-moi s'il vous plaît!

Merci, Sopolin

+0

il y a tellement de nombreux éditeurs libres sont là il suffit de cocher une de ces fckeditor google il – Nagu

Répondre

3

Voici comment je le ferais.

Dim linkLa As New LinkLabel 
linkLa.LinkColor = Color.Red 

Dim link As LinkLabel.Link = linkLa.Links.Add(0, 13, "http://www.stackoverflow.com") 
linkLa.Text = "Stackoverflow" 
AddHandler linkLa.LinkClicked, AddressOf Link_Clicked 

richTextBox1.Controls.Add(linkLa) 

Private Sub Link_Clicked(ByVal sender As Object, ByVal e As EventArgs) 
    MessageBox.Show("clicked") 
End Sub 
+0

J'accepte votre réponse, mais je veux montrer l'adresse du lien. – Sopolin

+0

vous pouvez simplement définir richTextBox1.DetectUrls = true, puis entrez simplement votre adresse en texte brut. Ou modifiez linkLa.Text à l'adresse au lieu du texte. –

0

J'ai une réponse pour vous. Cela vous permettra d'afficher l'adresse cible du lien sous forme d'info-bulle. (Petite bulle pop.) A part ça, c'est similaire à la réponse de Stan R.

  1. Mettez ce code sous le bouton « ajouter un lien » (ou quoi que vous l'appelez) dans votre programme

Note: Je mets des commentaires avant chaque ligne, il est donc plus facile à suivre!


'define the text and link targets 
Dim linktext As String = LinkTextbox.Text 'LinkTextbox is just the textbox where the user inputs the text of the link 
Dim linktarget As String = LinkTargetTextbox.Text 'LinkTargetTextBox is just the textbox where the user inputs the target URL of the link 

'Define the LinkLabel 
Dim lnk As New LinkLabel 
'if you want, you can set the different properties, like font or linkcolor, programmatically after defining the linklabel, for instance: 
lnk.LinkColor = Color.Blue 
'set tooltip 
lnk.Tooltip = linktarget 
'set the link target 
Dim lk As LinkLabel.Link = lnk.Links.Add(0, 13, linktarget) 
'set the link text 
lnk.Text = linktext 
'EventHandler 
AddHandler lnk.LinkClicked, AddressOf LinkClicked 
'Add the control to the richtextbox 
RichTextBox1.Controls.Add(lnk) 
'This is the Subroutine that the label will run when clicked (Make sure to put your "End Sub" before this, because it's not part of the button's subroutine) 
Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs) 
    'send link to the browser 
    Process.Start(linktarget) 
End Sub