【问题标题】:Stop ReSharper or Visual Studio from reformatting my code停止 ReSharper for Visual Studio 格式化我的代码
【发布时间】:2016-04-25 14:40:49
【问题描述】:

我目前正在开发一个 Windows 窗体应用程序,并在 MyForm.Designed.csInitializeComponent() 方法中设置标签文本。我将它设置为一个函数调用,所以它看起来像第一行,但它不断被重新格式化为第二行。第一行完美无缺,只是它正在重新格式化。

this.teamGroup.Text = LocalizedLanguage.GetValue("SelectedTeamLabel");
this.teamGroup.Text = "Selected Team";

此外,TabIndex 也会发生这种情况。

我有:

  • C# 6.0
  • Visual Studio 2015 社区
  • ReSharper 10.0.2

【问题讨论】:

    标签: c# visual-studio visual-studio-2015 resharper reformatting


    【解决方案1】:

    您可以在工具菜单中的选项下关闭 VS 中的自动代码格式化,选择 文本编辑器 -> -> 格式化 -> 常规 页面,然后取消选中那里的所有框。关闭所有自动格式化设置后,您仍然可以手动格式化。

    你可以在link1link2查看类似的东西

    【讨论】:

    • @Jacob,如果这对您有用,您可以接受答案。
    • 所以我可以这样做,但我将失去 VS 提供的所有重构。总的来说,我喜欢重构——只是在这些特定情况下不喜欢。
    • 你可以关闭你项目中不需要的功能,其他的照样工作。
    【解决方案2】:

    Jacob,你不应该手动修改 InitializeComponent 里面的代码。

    /// <summary>
    /// Required method for Designer support - do not modify
    /// contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    

    如果您想为组件添加一些内容,请使用以下方法:

    public YourForm ()
        {
            InitializeComponent();
            CustomInitializeComponent();
        }
    
        private void CustomInitializeComponent()
        {
            teamGroup.Text = LocalizedLanguage.GetValue("SelectedTeamLabel");
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-08
      • 2021-03-20
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 2016-02-01
      相关资源
      最近更新 更多