更改文本框中文本的前景色和背景色

发布于 2024-09-28 05:11:33 字数 118 浏览 2 评论 0原文

我正在使用 VB.NET 制作 C++ 代码编辑器应用程序。我想在用户键入关键字时更改关键字的颜色。另外,我正在寻找一种方法来突出显示某些代码行。

有没有办法更改文本框或富文本框中一段文本的前景色和背景色?

I'm making a C++ code editor application using VB.NET. I'd like to change the color of the keywords as the user types it. Also I'm looking for a way to highlight some lines of the code.

Is there a way to change the forecolor and backcolour of a piece of text inside a textbox or a rich textbox?

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

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

发布评论

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

评论(3

素手挽清风 2024-10-05 05:11:33

我真的不知道你想做什么,所以这里有一些选择。

如果您想要有关如何编写语法突出显示控件的分步教程,可以阅读以下文章:

  1. RichTextBox 中的语法突出显示第 1 部分第 2 部分
  2. 使用 C# 在 RichTextBox 中突出显示语法

有关用 VB.NET 编写的基本语法突出显示控件,请参阅本文:颜色语法控件 (VB.NET)。

如果您想要一个成熟的语法突出显示控件,有两个非常好的选择。它们是:

  1. 用于 WinForms 的 ScintillaNET 和;
  2. AvalonEdit 用于 WPF。
    • CodeProject 上有一个关于使用 AvalonEdit 的教程,因此请务必也检查一下。

I do not really know what you want to do so here are some options.

If you want a step by step tutorial on how to write a syntax highlighting control, you can read these articles:

  1. Syntax Highlighting in RichTextBox Part 1 and Part 2.
  2. Syntax Highlighting in RichTextBox using C#

For a basic syntax highlighting control written in VB.NET, see this article: Color Syntax Control (VB.NET).

There are two very good options if you want a fully-fledged syntax highlighting control. These are:

  1. ScintillaNET for WinForms and;
  2. AvalonEdit for WPF.
    • There is a tutorial on Using AvalonEdit on CodeProject so be sure to check that out as well.
一城柳絮吹成雪 2024-10-05 05:11:33

是的,在richtextbox控件中使用RTF。

来自http://www.biblioscape.com/rtf15_spec.htm

{\f1\cb1\cf2 This is colored text. The background is color
1 and the foreground is color 2.}

Yes, use RTF in the richtextbox control.

From http://www.biblioscape.com/rtf15_spec.htm

{\f1\cb1\cf2 This is colored text. The background is color
1 and the foreground is color 2.}
只有影子陪我不离不弃 2024-10-05 05:11:33

不幸的是,文本框的正常前景和背景属性无济于事,您需要手动使用富文本和格式(通过文本着色和突出显示算法)。

Unfortunately, the normal foreground and background properties of a textbox cannot help, and you need to use rich text and format that manually (through text coloring and highlighting algorithms).

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