如何在 C# TextBox 中添加 HTML 链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/330850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add HTML links in C# TextBox?
提问by beyerss
How can I put a link in a C# TextBox
? I have tried to put HTML tags in the box but instead of showing a link it shows the entire HTML tag. Can this be done with a TextBox
?
如何在 C# 中放置链接TextBox
?我试图将 HTML 标签放入框中,但它没有显示链接,而是显示了整个 HTML 标签。这可以用 a 来完成TextBox
吗?
采纳答案by doug
I would think about this a little bit. If you allow executable code in an editable control, the user, the user can execute ANYcode. This is generally a bad idea.
我会稍微考虑一下。如果您允许在可编辑控件中使用可执行代码,则用户可以执行任何代码。这通常是一个坏主意。
The behavior of the C# control is intentional to prevent the exact behavior that you are trying to create. A little creativity (such as parsing out links from the text box and creating a list of links next or below the text box) will provide a much safer application.
C# 控件的行为旨在防止您尝试创建的确切行为。一点创意(例如从文本框中解析链接并在文本框旁边或下方创建链接列表)将提供更安全的应用程序。
回答by Ian Jacobs
回答by Ryan Montgomery
I would try using an editable div and making it look like a text box. This would allow you to get user input and use links.
我会尝试使用可编辑的 div 并使其看起来像一个文本框。这将允许您获取用户输入并使用链接。
To make this easier, try JEditable.
为了让这更容易,请尝试JEditable。
回答by Patrick Desjardins
Use the RichTextBox, no need to build your own, it cames with VS
使用RichTextBox,无需自己构建,VS 自带
回答by Bruno Costa
If that is in windows forms and you really can't use the richtextbox, you can create a control with a linklabel inside of textbox.
如果这是在 Windows 窗体中并且您确实无法使用富文本框,则可以在文本框内创建一个带有链接标签的控件。
回答by Bruno Costa
For windows application, we can use a webbrowser control. However, for web applications Freetextbox will do the job.This is freely available dll.
对于 windows 应用程序,我们可以使用 webbrowser 控件。但是,对于 Web 应用程序,Freetextbox 可以完成这项工作。这是免费提供的 dll。