Text areas and hyperlinks?

I have two quick and easy questions in C # in Visual Studio. Firstly, there is something like a shortcut, but for the text area in the program? I would like to have a few lines of text in my program, but it may only seem that this will be done using the DotNetBar tag with wordwrap enabled.

Secondly, is there a way to have a hyperlink in the middle of the text without using a link label? If I wanted to create text, for example, β€œUpdating is available, visit http://example.com to download it!”, Is it possible to make a link without having to place the link label in the middle of the text?

+4
source share
4 answers

You can use LinkLabel and set the LinkArea property:

//LinkArea (start index, length) myLinkLabel.LinkArea = new LinkArea(37, 18); myLinkLabel.Text = "An update is available, please visit http://example.com to download it!"; 

The above link will do http://example.com a while the rest of the text is in normal mode.

Edit response to comment: There are various ways to handle a link. One way is to give a description link (URL) and then launch the URL using Process.Start.

 myLinkLabel.LinkArea = new System.Windows.Forms.LinkArea(37, 18); myLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(myLinkLabel_LinkClicked); myLinkLabel.Text = "An update is available, please visit http://example.com to download it!"; myLinkLabel.Links[0].Description = "http://example.com"; 

And the event handler can read the description and start the site:

 void myLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Process.Start(e.Link.Description); } 
+4
source

You can try RichTextBox control.

 string text = "This is the extract of text located at http://www.google.com and http://www.yahoo.com"; richTextBox1.Text = text; richTextBox1.ReadOnly = true; richTextBox1.LinkClicked += (sa, ea) => { System.Diagnostics.Process.Start(ea.LinkText); }; 
+2
source

You can use a normal label and make the AutoSize property false. And then adjust your width and height so that it turns around them.

+1
source

I assume that you are using a Windows application, not a web application.

In C #, you can create a normal text field by dragging it into your form, changing its property to multi-line, and make it read-only. What I always do.

How to add a link to text without a link. There is a way to add links to text fields. You can check out a pretty good tutorial at http://www.codeproject.com/KB/miscctrl/LinkTextBox.aspx/

0
source

Source: https://habr.com/ru/post/1388776/


All Articles