[英]How to change the font color in the textbox in C#?
If I want to upload a text file into the textbox and want to highlight certain words with a font color change, how can I do that without drawing the text? 如果我想将文本文件上传到文本框中并希望突出显示某些字体颜色更改的单词,如何在不绘制文本的情况下执行此操作?
Thank you. 谢谢。
Assuming WinForms, the ForeColor property allows to change all the text in the TextBox
(not just what you're about to add): 假设WinForms, ForeColor属性允许更改TextBox
中的所有文本 (而不仅仅是您要添加的内容):
TextBox.ForeColor = Color.Red;
To only change the color of certain words, look at RichTextBox . 要仅更改某些单词的颜色,请查看RichTextBox 。
RichTextBox will allow you to use html to specify the color. RichTextBox将允许您使用html指定颜色。 Another alternative is using a listbox and using the DrawItem event to draw how you would like. 另一种方法是使用列表框并使用DrawItem事件绘制您想要的方式。 AFAIK, textbox itself can't be used in the way you're hoping. AFAIK,文本框本身不能以你希望的方式使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.