locked
C# component's method naming conventions created by Visual Studio 2017 tool? RRS feed

  • Question

  • Dear All,

    I have a name conventions question,

    We have camelCasing for private variables, like private System.Windows.Forms.TextBox textBox1;

    and when we go to properties windows of this component, and double click a method, for example TextChanged, then the IDE tool create a method name "textBox1_TextChanged" for us,

    the name for the method is created by concatenated the component's name with the method's name, which is camelCasing.

    Since the naming convention for method is PascalCasing,

    why the Visual Studio do the conversion for us? Like "TextBox1_TextChanged"?

    Thus the IDE1006 Naming rule violation: These words must begin with upper case characters: textBox1_TextChanged doesn't show every time we create a method.

    Thanks and Best regards,

    E-John

    namespace TestWinFormTextBoxStringColor
    {
        partial class Form1
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.textBox1 = new System.Windows.Forms.TextBox();
                this.button1 = new System.Windows.Forms.Button();
                this.richTextBox1 = new System.Windows.Forms.RichTextBox();
                this.SuspendLayout();
                // 
                // textBox1
                // 
                this.textBox1.Location = new System.Drawing.Point(183, 152);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(100, 22);
                this.textBox1.TabIndex = 0;
                this.textBox1.Text = "TestNodeName";
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(47, 84);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 1;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // richTextBox1
                // 
                this.richTextBox1.Location = new System.Drawing.Point(47, 37);
                this.richTextBox1.Name = "richTextBox1";
                this.richTextBox1.Size = new System.Drawing.Size(104, 23);
                this.richTextBox1.TabIndex = 2;
                this.richTextBox1.Text = "TestNodeName";
                this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
                this.richTextBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.richTextBox1_KeyDown);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(311, 186);
                this.Controls.Add(this.richTextBox1);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.textBox1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.ResumeLayout(false);
                this.PerformLayout();
    
            }
    
            #endregion
    
            private System.Windows.Forms.TextBox textBox1;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.RichTextBox richTextBox1;
        }
    }

            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }

    Tuesday, July 16, 2019 6:11 AM

Answers

  • Hi E-John,

    In VS2017, the format of the method generated by "properties windows" is "control name" + "PascalCase event name".

    In VS2019, the format is "PascalCase control name" + "PascalCase event name".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by E-John Tuesday, July 16, 2019 7:12 AM
    Tuesday, July 16, 2019 6:27 AM

All replies

  • Hi E-John,

    In VS2017, the format of the method generated by "properties windows" is "control name" + "PascalCase event name".

    In VS2019, the format is "PascalCase control name" + "PascalCase event name".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by E-John Tuesday, July 16, 2019 7:12 AM
    Tuesday, July 16, 2019 6:27 AM
  • Dear Kyle,

    Does it mean the name conventions for private variable is changed since Visual Studio 2019?

    private variable is changed to PascalCase?

    Thanks and Best regards,

    E-John


    • Edited by E-John Tuesday, July 16, 2019 6:37 AM
    Tuesday, July 16, 2019 6:36 AM
  • Hi E-John,

    As I know, now only the method generated by "properties windows" is different from VS2017. The default format of the control name is still "camelCasing".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 16, 2019 6:53 AM
  • Hi Kyle,

    Thanks for your helps.

    Best regards,

    E-John

    Tuesday, July 16, 2019 7:11 AM