如何检测在 WPF 应用程序的 RichTextBox 中写入或粘贴的 URL [英] How to detect URLs written or pasted in a RichTextBox in WPF application

查看:63
本文介绍了如何检测在 WPF 应用程序的 RichTextBox 中写入或粘贴的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时用户会在聊天应用程序中聊天时输入网站 URL.我需要让 RichTextBox 自动检测这些 URL,但我不知道如何.通用文本框不检测 URL,所以我用 RichTextBox 代替.我知道 RichTextBoxes 可以检测 URL,但我不知道如何检测.有人可以建议我怎么做吗?

Sometimes a user will type a website URL while chatting in a Chat Application. I need to make the RichTextBox detect these URLs automatically, but I do not know how. General TextBox does not detect URLs, so i have used RichTextBox instead. I know RichTextBoxes can detect URLs but I don't know how. Can anybody suggest how I might do this?

推荐答案

正如 schoola 所指出的,WPF RichTextBox 不会自动检测 URL.但是 本文描述了可用于此目的的自定义 RichTextBox 的一个相当简单(150 行)的实现.

As schoola pointed out, the WPF RichTextBox does not auto-detect URLs. However this article describes a fairly simple (150 line) implementation of a custom RichTextBox that can be used for this very purpose.

这篇关于如何检测在 WPF 应用程序的 RichTextBox 中写入或粘贴的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆