PrepAway - Latest Free Exam Questions & Answers

What should you do to modify the form to invoke this method without interfering with the existing operations o

You are customizing a Windows Form. When the user clicks any button, you want the application to log information about the user’s actions by calling a method with the following signature.

public void ctl_Click(object sender, EventArgs e)

You want the form to invoke this method when any Button control is clicked and only when a Button control is clicked. You need to modify the form to invoke this method without interfering with the existing operations of the application. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Add the following code to the form initialization.
foreach (Control ctl in this.Controls) {
if (ctl is Button) {
ct1.Click += new EventHandler(ct1_Click);
}
}

B.
Add the following code to the form initialization.
this.Click += new EventHandler(ct1_Click);

C.
Use the Properties dialog box to set the Click event for each Button control on the form to the ctl_Click method.

D.
Use the Properties dialog box to set the Click event of the form to the ctl_Click method.


Leave a Reply