在Visual Studio中更改选定文本的文本颜色 [英] Change text color for Selected Text in Visual Studio

查看:699
本文介绍了在Visual Studio中更改选定文本的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
我无法在Visual Studio 2010中编辑选定的文本前景色.有人知道该怎么做吗?

Possible Duplicate:
I can't edit selected text foreground color in Visual Studio 2010. Anyone know how to do this?

选项->环境->字体和颜色对话框中,可以在显示项目"列表框中选择Selected Text,但这仅允许您更改项目"背景属性.

In the Options->Environment->Fonts and Colors dialog you can choose Selected Text in the Display Items listbox, but this only allows you to change the Item background property.

如何更改文本颜色,例如选择一个项目时可以在蓝色背景上显示白色文本?另外,还有一种方法可以使文本加粗(Bold框也被禁用).

How does one change the text color, so that for example I can have white text on a blue background when I select an item? Also, is there a way to bold the text (the Bold box is disabled also).

注意:这是一个问题,它询问背景颜色的变化.

Note: Here is the question that asks about the background color change.

推荐答案

VS2010编辑器中的前景色不是在一个地方设置的,而是在选项"表单中的很多地方设置的.如果您安装了Resharper,它还会设置一些前景属性. VS2010这样做的原因是,即使选中它们,前台中的单个项目(单词)也可以根据其类型(例如,注释,值类型,枚举等)表达不同的颜色.换句话说,VS2010对这些特定类型的前景色优先于一般选定的文本颜色格式.

The foreground color in the VS2010 editor is not set in one place but in many within the Options Form. If you have Resharper installed it also sets some foreground properties. The reason VS2010 does this is to allow individual items (words) within the foreground to express different colors depending on their type (e.g. comments, value types, enums etc.) even when they are selected. In other words VS2010 applies a priority to the foreground color for these specific types over the generic selected text color format.

例如,当您查看字体和颜色对话框时,您会注意到用户类型条目.在我的VS2010上,其RGB值为RGB(43、145、175),看起来像蓝绿色.如果我将颜色更改为红色,则编辑器前景色的用户类型"将更改为红色,即使在选择区域中,用户类型也将保持红色.

For instance, when you look at the Fonts and Colors dialog you will notice the entry for User Types. On my VS2010 its RGB value is RGB(43, 145, 175) which looks like teal. If I change that color to Red, the User Types on my editor's foreground color changes to Red and remains Red even when with the selection area.

在某些情况下,VS2010将覆盖前景色,例如将断点应用于行.在我的VS2010上,无论行中的术语如何,在编辑模式下启用的断点都具有白色前景色.

In some instances VS2010 will override the foreground color such as applying a breakpoint to a line. On my VS2010 enabled breakpoints when in editing mode have a white foreground color, regardless of the terms in the line.

要回答有关如何更改所有选定文本的前景色的问题,VS2010不提供开箱即用的支持.

To answer your question of how one would change the foreground color for all selected text, VS2010 does not support this out of the box.

我在此处中概述了VS2010扩展.我按原样使用示例代码并添加了以下行:

I wrote a VS2010 Extension as outlined here. I used the example code as is and added the lines:

        selectedText[EditorFormatDefinition.ForegroundBrushId] = Brushes.Green;
        formatMap.SetProperties("Selected Text", selectedText);

...但是这并未将所选文本的前景色更改为绿色.它保持黑色.这可能是由于VS2010 WPF编辑器对每种格式使用了优先顺序,以及一种或多种其他格式会覆盖所选的文本前景色.

...but this did not change the foreground color of selected text to green. It stayed black. This is probably due to the VS2010 WPF editor using a Priority Order for each format and one or more other formats overriding the selected text foreground color.

这篇关于在Visual Studio中更改选定文本的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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