Visual studio change curly brace style(highlight braces background) and display it on new line

Lionsure 2020-07-17 Original by the website

When you click in front of the braces(brackets), Visual Studio will automatically add a background to them to identify a pair of brackets, so that we can identify the scope of code. However, the default background color of Visual Studio braces is usually lighter(especially for highlight monitors), and there is no background color at all, which requires a darker color.

In terms of the background color of brackets in Visual Studio, it refers to all brackets(curly brackets {}, brackets (), square brackets []) as bracket matching(Rectangle), as long as the background color of square brackets(or Brace Matching) is set, the background color of all brackets is set, see the setting method below.

 

I. Visual studio change curly brace style(highlight braces background)

1. Quick settings

"Tools" menu → Options → Environment → Fonts and Colors → Select "Brace Matching or Brace Matching(Rectangle)" under "Display items" → select a "Background Color" → OK → Finish.

 

2. Detailed steps

1. Select the "Tools" menu → Options in turn, and open the dialog box as shown in Figure 1:

Visual studio change curly brace style

Figure 1

2. Expand "Environment", select "Fonts and Colors", select "Brace Matching or Brace Matching(Rectangle)" under "Display items", as shown in Figure 1.

3. Select a " background color", such as "Lime", there is a preview under the "Sample", you can change a color if you don't like it.

 

4. Click "OK". After a while, the setting will take effect. Click in front of the braces. The "Lime" background color has been displayed, as shown in Figure 2:

Visual studio highlight braces background

Figure 2

5. Clicking before the brackets also shows the "Lime" background, as shown in Figure 3:

Figure 3

Clicking the square brackets will also display a "Lime" background, don't put the picture. You can open the Visual Studio setting experience yourself.

 

 

II. Visual studio braces on new line

1. Click "Tools", select "Options" in the pop-up menu, open the "Options" dialog box, select "Text Editor" → C# → Code Style → Formatting → New Lines, check the "Place open brace on new line for types", as shown in Figure 4:

Visual studio change brackets style(highlight braces background)

Figure 4

2. In the preview box below, the braces have been displayed on the new line. In addition to "Place open brace on new line for types", there are multiple options, you can preview one by one, check the desired.

In addition to placing braces in different positions, keywords(such as esle, catch, and finally) can also be used, for example, display esle to a new line, as shown in Figure 5:

Visual studio braces on new line

Figure 5