![](/img/trans.png)
[英]how to remove curly braces from a namespace in visual studio 2022
[英]Curly braces autocomplete in Visual Studio 2012
剛剛從vs10遷移到vs12,似乎花括號與其他一些功能完全一致,如C#(?)中的縮進,例如類型:
public static void myFunc() {
在visual studio 10中,它會自動為它添加閉合花括號。 是否有一些電動工具或某些東西可以解決這個並給出相同的行為? Brace Completer需要在函數后按Enter鍵才能添加結束括號。
此外,在工具 - >選項 - >文本編輯器 - > c# - >格式化 - >自動格式化已完成的塊開啟}
默認情況下已打開..
如果有人在VS 2013中遇到此問題,那么現在有一個設置。 我只是重置我的VS設置,它又開始重新完成我的大括號。 對我來說,這不是生產力工具。 你可以在這里打開/關閉它:
默認情況下,Visual Studio 2010不會這樣做(至少在我的情況下不是這樣)。 您確定沒有使用像Productivity Power Tools這樣的擴展程序
這個支持VS2012: http ://visualstudiogallery.msdn.microsoft.com/0e33cb22-d4ac-4f5a-902f-aff5177cc94d
生產力2012年的Power Tools現已上市,有自動支撐完成,OP幾乎肯定使用2010版本。
如果您以前沒有使用它,您可以打開/關閉它在選項>生產力電動工具中添加的每個功能。
這是使用C#為RichTextBox創建Auto Complete Brackets的代碼。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Auto_Complete_Brackets
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//declare isCurslyBracesKeyPressed variable as Boolean and assign false value
//to check { key is pressed or not
public static Boolean isCurslyBracesKeyPressed = false;
//richTextBox1 KeyPress events
// if key (,{,<,",',[ is pressed then insert opposite key to richTextBox1 at Position SelectionStart+1
// add one line after inserting, e.Handled=true;
//finally set SelectionStart to specified position
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
String s = e.KeyChar.ToString();
int sel = richTextBox1.SelectionStart;
if (checkBox1.Checked == true)
{
switch (s)
{
case "(": richTextBox1.Text = richTextBox1.Text.Insert(sel, "()");
e.Handled = true;
richTextBox1.SelectionStart = sel + 1;
break;
case "{":
String t = "{}";
richTextBox1.Text = richTextBox1.Text.Insert(sel, t);
e.Handled = true;
richTextBox1.SelectionStart = sel + t.Length - 1;
isCurslyBracesKeyPressed = true;
break;
case "[": richTextBox1.Text = richTextBox1.Text.Insert(sel, "[]");
e.Handled = true;
richTextBox1.SelectionStart = sel + 1;
break;
case "<": richTextBox1.Text = richTextBox1.Text.Insert(sel, "<>");
e.Handled = true;
richTextBox1.SelectionStart = sel + 1;
break;
case "\"": richTextBox1.Text = richTextBox1.Text.Insert(sel, "\"\"");
e.Handled = true;
richTextBox1.SelectionStart = sel + 1;
break;
case "'": richTextBox1.Text = richTextBox1.Text.Insert(sel, "''");
e.Handled = true;
richTextBox1.SelectionStart = sel + 1;
break;
}
}
}
// richTextBox1 Key Down event
/*
* when key { is pressed and {} is inserted in richTextBox
* and isCurslyBracesKeyPressed is true then insert some blank text to richTextBox1
* when Enter key is down
* it will look like this when Enter key is down
{
|
}
* */
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
int sel = richTextBox1.SelectionStart;
if (e.KeyCode == Keys.Enter)
{
if(isCurslyBracesKeyPressed==true)
{
richTextBox1.Text = richTextBox1.Text.Insert(sel, "\n \n");
e.Handled = true;
richTextBox1.SelectionStart = sel + " ".Length;
isCurslyBracesKeyPressed = false;
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.