为了使用 winapi 显示推文,我可以选择什么最佳控件?

发布于 2024-11-10 10:21:28 字数 539 浏览 3 评论 0原文

该控件需要能够在多行上绘制文本,响应 URL 或 @user 标签等的点击,这些都需要具有不同的颜色才能脱颖而出。

第一个明显的选择是 Richedit 控件,但我遇到了很多问题。首先,我希望文本不可选择并且输入被禁用。后者很简单,但我发现禁止选择文本的唯一方法是禁用该控件。在这种情况下,我不知道如何将背景颜色从默认的灰色更改为白色。此外,当控件被禁用时,我从 richedit 免费获得的所有可点击链接功能都会停止工作。

你说我的选择是什么?我对尝试使用 TextOut 来制作自己的控件非常谨慎。这可能会让我想哭。

编辑: 到目前为止,我还没有考虑允许用户选择文本作为选项,因此只读模式似乎没什么用。我脑子里就是这么计划的。我绝对不希望有一个闪烁的插入符号,所以我四处寻找,发现我可以在 Richedit 的 WM_SETFOCUS 上调用 HideCaret (通过子类化它)并返回 0。这样就永远摆脱了插入符号。讽刺的是,这也消除了用鼠标选择任何内容的能力,这几乎正是我最初希望的行为。我不知道我是否完全反对禁止选择。我会回到那个。现在剩下的就是弄清楚我是否可以覆盖将鼠标悬停在文本上时光标图像更改的行为。

The control needs to be able to paint text on several lines, respond to clicks on URLs or @user tags, etc, which need to have a different color in order to stand out.

The first obvious choice was a richedit control, but I ran into many issues with this. First off, I would like the text to be nonselectable and input to be disabled. The latter is easy, but the only way I found to disallow selecting text is to disable the control. In that case I can't figure out how to change the background color from the default gray to white. In addition, all the clickable link functionality I get for free from richedit stops working when the control is disabled.

What would you say are my options? I'm very wary of trying to use TextOut to make my own control. That might make me want to cry.

EDIT:
Until now I didn't consider allowing the user to select text as an option, so the read only mode didn't seem useful. I just had it planned in my head that way. I definitely want there to not be a blinking caret, so I poked around and found that I can call HideCaret on WM_SETFOCUS of the richedit (by subclassing it) and returning 0. That got rid of the caret for good. Ironically, that also got rid of the ability to select anything with the mouse, which is almost exactly the behavior I was hoping for in the first place. I don't know if I'm entirely opposed to disallowing selection though. I'll get back to that. Now all that's left is to figure out if I can override the behavior of the cursor's image changing when hovering over text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一萌ing 2024-11-17 10:21:28

您可以使用 Webbrowser 控件 和只需构建显示您想要的内容的 HTML 即可。

You could use the Webbrowser control and just build the HTML that displays what you want.

顾挽 2024-11-17 10:21:28

我讨厌禁用控件的选项,为什么不让我有权选择要复制的文本的一部分。

无论如何,您可以将颜色设置为接近白色FEFEFE,它应该可以工作,只是不是纯白色。

RichEdit 控件没有“只读”模式吗?将停止输入,但选择文本并单击链接。

I'd hate the option with the control disabled, why not let me have access to select a part of the text to copy.

Anyway, you can set the colour to near white FEFEFE and it should work, just not pure white.

Doesn't the RichEdit control have a 'readonly' mode, will stop input but let select the text and click on links.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文