Visual studio style windows

Практическое руководство. Персонализация интегрированной среды разработки и редактора Visual Studio How to: Personalize the Visual Studio IDE and the editor

Из этой статьи вы узнаете, как переключить цветовую тему Visual Studio по умолчанию на темный режим. In this how-to article, we’ll customize the Visual Studio color theme from the default blue theme to the dark theme. Мы также настроим цвета для двух различных типов текста в редакторе кода. Then, we’ll customize the colors for two different types of text in the code editor.

Установите Visual Studio бесплатно со страницы скачиваемых материалов Visual Studio, если еще не сделали этого. If you haven’t already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

Установите Visual Studio бесплатно со страницы скачиваемых материалов Visual Studio, если еще не сделали этого. If you haven’t already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

Настройка цветовой темы для интегрированной среды разработки Set the color theme for the IDE

По умолчанию в пользовательском интерфейсе Visual Studio установлена тема Синяя. The default color theme for Visual Studio’s user interface is called Blue. Давайте изменим ее на тему Темная. Let’s change it to Dark.

В строке меню, где расположены разделы Файл и Изменить, выберите Средства > Параметры. On the menu bar, which is the row of menus such as File and Edit, choose Tools > Options.

Откройте страницу параметров Окружение > Общие, измените значение Цветовая тема на Темная и щелкните ОК. On the Environment > General options page, change the Color theme selection to Dark, and then choose OK.

Цветовая тема для всей среды разработки (IDE) Visual Studio изменяется на Темная. The color theme for the entire Visual Studio development environment (IDE) changes to Dark.

Вы можете выбрать дополнительные предопределенные темы, установив редактор цветовых тем Visual Studio из Visual Studio Marketplace. You can install additional predefined themes by installing the Visual Studio Color Theme Editor from the Visual Studio Marketplace. Когда вы установите это средство, в раскрывающемся списке Цветовая тема появятся дополнительные темы. After you install this tool, additional color themes appear in the Color theme drop-down list.

Вы можете создать собственные темы, установив конструктор цветовых тем Visual Studio из Visual Studio Marketplace. You can create your own themes by installing the Visual Studio Color Theme Designer from the Visual Studio Marketplace.

Изменение цветов текста в редакторе Change text colors in the editor

Теперь настроим несколько цветов текста для редактора. Now we’ll customize some text colors for the editor. Сначала создадим XML-файл, чтобы просмотреть цвета по умолчанию. First, let’s create a new XML file to see the default colors.

Читайте также:  Зеркальное отображение экрана windows

В строке меню выберите Файл > Создать > Файл. From the menu bar, choose File > New > File.

В диалоговом окне Новый файл в разделе Общие выберите XML-файл и нажмите кнопку Открыть. In the New File dialog box, under the General category, choose XML File, and then choose Open.

Вставьте приведенный ниже XML-код под строкой с . Paste the following XML below the line that contains .

Обратите внимание, что цвет номеров строк бирюзовый, а атрибутов XML (например id=»bk101″ ) — голубой. Notice that the line numbers are a turquoise-blue color, and the XML attributes (such as id=»bk101″ ) are a light blue color. Давайте изменим цвет этих элементов. We’re going to change the text color for these items.

Чтобы открыть диалоговое окно Параметры, в строке меню выберите Сервис > Параметры. To open the Options dialog box, choose Tools > Options from the menu bar.

В разделе Среда выберите категорию Шрифты и цвета. Under Environment, choose the Fonts and Colors category.

Обратите внимание, что в поле Показать параметры для указано значение Текстовый редактор,—именно это нам и нужно. Notice that the text under Show settings for says Text Editor—this is what we want. Раскройте список, чтобы узнать, для каких еще элементов можно настроить шрифты и цвет текста. Expand the drop-down list just to see the extensive list of places where you can customize fonts and text color.

Чтобы изменить цвет номера строки, в списке Отображение элементов выберите Номер строки. To change the color of the line numbers text, in the Display items list, choose Line Number. В поле Основной цвет элемента выберите Оливковый. In the Item foreground box, choose Olive.

Некоторые языки имеют собственные параметры шрифтов и цветов. Some languages have their own specific fonts and colors settings. Если вы являетесь разработчиком на C++ и хотите изменить цвет, используемый для выделения функций, найдите элемент Функции C++ в списке Отображение элементов. If you are a C++ developer and you want to change the color used for functions, for example, you can look for C++ Functions in the Display items list.

Прежде чем закрыть диалоговое окно, давайте также изменим цвет атрибутов XML. Before we exit out of the dialog box, let’s also change the color of XML attributes. В списке Отображение элементов прокрутите вниз до элемента Атрибут XML и выберите его. In the Display items list, scroll down to XML Attribute and select it. В поле Основной цвет элемента выберите Травяной. In the Item foreground box, choose Lime. Нажмите ОК, чтобы сохранить изменения и закрыть диалоговое окно. Choose OK to save our selections and close the dialog box.

Теперь цвет номеров строк станет оливковым, а цвет XML-атрибутов — ярко-травяным. The line numbers are now an olive color, and the XML attributes are a bright, lime green. Если открыть файл другого типа, например файл с кодом C++ и C#, цвет номеров строк также станет оливковым. If you open another file type, such as a C++ or C# code file, you’ll see that the line numbers also appear in the olive color.

Читайте также:  Драйвер esmart token usb 64k для windows

Мы изучили только некоторые способы настраивать цвета в Visual Studio. We explored just a couple ways of customizing the colors in Visual Studio. Ознакомьтесь с другими возможностями в диалоговом окне Параметры, чтобы настроить Visual Studio в соответствии со своими предпочтениями. We hope that you’ll explore the other customization options in the Options dialog box, to truly make Visual Studio your own.

Code style preferences

You can define code style settings per-project by using an EditorConfig file, or for all code you edit in Visual Studio on the text editor Options page. For C# code, you can also configure Visual Studio to apply these code style preferences using the Code Cleanup (Visual Studio 2019) and Format Document (Visual Studio 2017) commands.

This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Editor behavior in Visual Studio for Mac.

Code styles in EditorConfig files

Code style settings for .NET can be specified by adding an EditorConfig file to your project. EditorConfig files are associated with a codebase rather than a Visual Studio personalization account. Settings in an EditorConfig file take precedence over code styles that are specified in the Options dialog box. Use an EditorConfig file when you want to enforce coding styles for all contributors to your repo or project.

You can manually populate your EditorConfig file, or you can automatically generate the file based on the code style settings you’ve chosen in the Visual Studio Options dialog box. This options page is available at Tools > Options > Text Editor > [C# or Basic] > Code Style > General. Click Generate .editorconfig file from settings to automatically generate a coding style .editorconfig file based on the settings on this Options page.

Code styles in the Options dialog box

Code style preferences can be set for all of your C# and Visual Basic projects by opening the Options dialog box from the Tools menu. In the Options dialog box, select Text Editor > [C# or Basic] > Code Style > General.

Each item in the list shows a preview of the preference when selected:

Options set in this window are applicable to your Visual Studio personalization account and aren’t associated with a particular project or codebase. In addition, they aren’t enforced at build time, including in continuous integration (CI) builds. If you want to associate code style preferences with your project and have the styles enforced during build, specify the preferences in an .editorconfig file that’s associated with the project.

Preference and severity

For each code style setting on this page, you can set the Preference and Severity values using the drop-downs on each line. Severity can be set to Refactoring Only, Suggestion, Warning, or Error. If you want to enable Quick Actions for a code style, ensure that the Severity setting is set to something other than Refactoring Only. The Quick Actions light bulb , error light bulb , or screwdriver icon appears when a non-preferred style is used, and you can choose an option on the Quick Actions list to automatically rewrite code to the preferred style.

Читайте также:  Command and conquer для linux

Enforce code styles on build

Starting in Visual Studio 2019 version 16.8, which includes the .NET 5.0 RC2 SDK, you can enforce the .NET coding conventions on build for all .NET projects. At build time, .NET code style violations will appear as warnings or errors with an «IDE» prefix. This enables you to strictly enforce consistent code styles in your codebase.

Apply code styles

You can configure the Format Document command (Edit > Advanced > Format Document) to apply your code style settings (from an EditorConfig file or Code Style options) along with the regular formatting that it does (such as indentation). If an .editorconfig file exists for the project, those settings take precedence.

Applying code styles by using the Format Document command is only available for C# code files. This is an experimental feature.

Configure which settings you want Format Document to apply on the Formatting options page.

Rules configured with a severity of None don’t participate in code cleanup but can be individually applied via the Quick Actions and Refactorings menu.

The first time you trigger the Format Document command, a yellow info bar prompts you to configure your code cleanup settings.

For C# code files, Visual Studio 2019 has a Code Cleanup button at the bottom of the editor (keyboard: Ctrl+K, Ctrl+E) to apply code styles from an EditorConfig file or from the Code Style options page. If an .editorconfig file exists for the project, those are the settings that take precedence.

Rules configured with a severity of None don’t participate in code cleanup but can be individually applied via the Quick Actions and Refactorings menu.

First, configure which code styles you want to apply (in one of two profiles) in the Configure Code Cleanup dialog box. To open this dialog box, click the expander arrow next to the code cleanup broom icon and then choose Configure Code Cleanup.

After you’ve configured code cleanup, you can either click on the broom icon or press Ctrl+K, Ctrl+E to run code cleanup. You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

If you want your code style settings to be applied every time you save a file, you may like the Code Cleanup on Save extension.

Оцените статью