0

I made an chat application that uses listBox and each time someone sends a new message the text is displayed in the list box, I want to make so if someone sends either message starting with http or https to be clickable and open the link in an default browser. I use Visual Studio 2019 Enterprise. I tried searching the web but didn't find what I was looking for and I have no idea how to do it myself. Any help highly appreciated.

EDIT: I want to make links clickable that are displayed in an listBox screenshot its an win forms application

nnaem
  • 177
  • 1
  • 2
  • 12
  • 1
    is this a web or desktop application??? – krisam May 11 '21 at 18:23
  • You can maybe use System.Diagnostics.Process.Start("http://google.com"); to open the link after you get it as string. https://stackoverflow.com/questions/4580263/how-to-open-in-default-browser-in-c-sharp. – Stefan27 May 11 '21 at 18:27
  • Hey, please add a little bit more information about the context. Your question doesn't help to illustrate the situation. Fix the tag and briefly describe which platform you are working on before someone gives a downvote and demotivates you. – Mahmudul Hasan May 11 '21 at 18:27
  • ill edit my question – nnaem May 11 '21 at 18:32

1 Answers1

0

1. Get the selected item as string - listBox1.SelectedItem.ToString(); https://stackoverflow.com/a/18065641/13028588

2. Find word that has http:// or https:// C# - Maybe this can help https://learn.microsoft.com/en-us/dotnet/csharp/how-to/search-strings https://learn.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-5.0 Find text in string with C#

3. After you get the link as string you can use this -System.Diagnostics.Process.Start("https://thelink.com"); - How to open in default browser in C#

This is just to point you in the right direction hopefully.

Stefan27
  • 845
  • 8
  • 19
  • can you explain the first step better, also the second step doesnt work anymore, or its just me, if i try to do process.start("link"); it throws an error in visual studio and doesnt work – nnaem May 11 '21 at 18:52
  • Do you have using System.Diagnostics; in the class – Stefan27 May 11 '21 at 18:55
  • yes, i used it before and it threw an error with process.start if i've put a link in it, the last time i did was make an batch file and write into it Start "link" and it worked – nnaem May 12 '21 at 05:53
  • System.Diagnostics.Process.Start(" https://thelink.com "); Works in WinForms. I have used it and it works. About the batch file I dont understand because this is not Winforms this is CMD. – Stefan27 May 12 '21 at 08:02
  • yeah, process.start didnt work because i was in c# console app i think, sorry – nnaem May 12 '21 at 09:48