Secret ingredients to quality software

Do you always check your button's event handler hook-up?

Last updated by Brady Stroud [SSW] on 27 Apr 2021 01:01 am (7 months ago) See History

Sometimes the button's event handler hook-up could be lost by accident, but there will be no warning or error reported when you compile your applications.

this.button1 = new System.Windows.Forms.Button();
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(419, 115);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 60;
this.button1.UseVisualStyleBackColor = true;

Bad Example - the event handler hook-up is lost, so there will be no response after you click the button

this.btnResetAll = new System.Windows.Forms.Button();
this.btnResetAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnResetAll.Location = new System.Drawing.Point(417, 410);
this.btnResetAll.Name = "btnResetAll";
this.btnResetAll.Size = new System.Drawing.Size(75, 23);
this.btnResetAll.TabIndex = 54;
this.btnResetAll.Text = "Reset &All";
this.btnResetAll.UseVisualStyleBackColor = true;
this.btnResetAll.Click += new System.EventHandler(this.btnResetAll_Click);

Good Example : keep the event handler hook-up together with the initialization of the button

Adam CoganAdam Cogan

We open source. Powered by GitHub