Search code examples
c#visual-studiovisual-studio-2015resharperreformatting

Stop ReSharper or Visual Studio from reformatting my code


I am currently working on a Windows Form application, and setting the text of labels in the InitializeComponent() method of MyForm.Designed.cs. I'm setting it to a function call so it looks like the first line, but it keeps getting reformatted into the second line. The first line works perfectly, it's just that it's getting reformatted.

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

Additionally, this is also happening for the TabIndex as well.

I have:

  • C# 6.0
  • Visual Studio 2015 Community
  • ReSharper 10.0.2

Solution

  • Jacob, you shouldn't modify the code inside InitializeComponent manually.

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

    If you want to add something for the components use the following approach:

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