jacobvoller.com
jacobvoller.com

Reputation: 516

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:

Upvotes: 0

Views: 129

Answers (2)

Sergey_T
Sergey_T

Reputation: 598

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");
    }

Upvotes: 0

sumngh
sumngh

Reputation: 566

You can switch off automatic code formatting in VS under Options in Tools menu, selecting the Text Editor -> -> Formatting -> General page, and unchecking all the boxes there. You will still be able to manually format when all of the auto-formatting settings are turned off.

You can check the similar thing here link1 or link2

Upvotes: 1

Related Questions