2012-08-29 54 views
25

從VS10到VS12就遷移,好像大括號的旁邊,在C# 例如,鍵入一些其他的功能,如壓痕是完全打破(?):大括號自動完成在Visual Studio 2012

public static void myFunc() { 

在visual studio 10中,它會自動爲它添加大括號。 是否有一些電動工具或某些可以解決這個問題,並給出相同的行爲? Brace Completer需要按Enter鍵後才能添加花括號。

在工具 - >選項 - >文本編輯器 - >

而且C# - > formatting->自動設置格式} 完成塊默認開啓..

+4

「工具 - >選項 - >文本編輯器 - > C# - 上> formatting-> automaticcly格式完成塊}」 不自動添加結尾括號。它格式化所附的代碼...正確縮進等,當你添加結束的大括號。 – Thelonias

+2

謝謝,我需要這個關閉汽車大括號,真的很煩人! – DevDave

+4

我有相反的問題。 2013年似乎是默認這樣做的。你怎麼把這個關掉!? – BrainSlugs83

回答

22

Visual Studio 2010中沒有做到這一點的默認(至少不是在我的情況)。你確定你沒有使用像Productivity Power Tools

這一個擴展支持VS2012: http://visualstudiogallery.msdn.microsoft.com/0e33cb22-d4ac-4f5a-902f-aff5177cc94d

+1

感謝但大括號完成者需要回車來完成花括號,這不是我正在尋找的行爲。 – aromasca

+1

我假設你正在使用第一個鏈接上看起來不像VS2012更新的鏈接。這似乎並不需要按輸入。 「自動大括號完成通過在爲VB和C#鍵入打開結構時自動插入結束代碼結構來提高編寫代碼的效率。」 – coolmine

42

如果有人對VS 2013有這個問題,現在有一個設置。我只是重置我的VS設置,並開始完成我的大括號。對我而言,這不是生產力電動工具。您可以打開/關閉它在這裏:

enter image description here

+12

感謝上帝,如果你不習慣使用它,這是令人難以置信的煩人。 –

+0

好吧,也許如果Visual Studio正確地返回這個搜索字詞「大括號」...(它不) – FriendlyGuy

-1

下面是創建使用C#進行RichTextBox的自動完成方括號中的代碼。

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; 
       } 
      } 
     } 
    } 
} 
+2

這是甚至相關的問題? – VSG24

相關問題