简体   繁体   English

如何在 C# 中使 listBox 中的链接可点击

[英]How do I make links in listBox clickable in C#

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.我制作了一个使用 listBox 的聊天应用程序,每次有人发送新消息时,文本都会显示在列表框中,我想这样做,如果有人发送以 http 或 https 开头的消息,则可以单击并默认打开链接浏览器。 I use Visual Studio 2019 Enterprise.我使用 Visual Studio 2019 企业版。 I tried searching the web but didn't find what I was looking for and I have no idea how to do it myself.我尝试搜索 web 但没有找到我要找的东西,我不知道自己该怎么做。 Any help highly appreciated.任何帮助高度赞赏。

EDIT: I want to make links clickable that are displayed in an listBox screenshot its an win forms application编辑:我想让显示在 listBox屏幕截图中的链接可点击,它是一个 win forms 应用程序

1. Get the selected item as string - listBox1.SelectedItem.ToString(); 1. 以字符串形式获取选中的项目 - listBox1.SelectedItem.ToString(); https://stackoverflow.com/a/18065641/13028588 https://stackoverflow.com/a/18065641/13028588

2. Find word that has http:// or https:// C# - Maybe this can help https://docs.microsoft.com/en-us/dotnet/csharp/how-to/search-strings https://docs.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-5.0 Find text in string with C# 2. Find word that has http:// or https:// C# - Maybe this can help https: //docs.microsoft.com/en-us/dotnet/csharp/how-to/search-strings https:// docs.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-5.0 使用 C# 在字符串中查找文本

3. After you get the link as string you can use this - System.Diagnostics.Process.Start("https://thelink.com"); 3.获得字符串形式的链接后,您可以使用它 - System.Diagnostics.Process.Start("https://thelink.com"); - How to open in default browser in C# - 如何在 C# 的默认浏览器中打开

This is just to point you in the right direction hopefully.这只是希望为您指明正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM