Base Virtual Event Being Called Twice

E

Edwin

Hello Everyone. Below is the code that is in question.

--- BEGIN CODE WITHIN INHERITED FORM ---
protected virtual void OnFormClosing(object sender, FormClosingEventArgs e)
{
switch (e.CloseReason)
{
case CloseReason.UserClosing:
if (this.AskUserIfOkayToClose() == true)
{ this.ExecuteApplicationCloseProcedures(); }
else
{ e.Cancel = true; }
break;

case CloseReason.ApplicationExitCall:
this.ExecuteApplicationCloseProcedures();
break;
default:
e.Cancel = true;
break;
}
}
}

protected virtual void buttonNext_Click(object sender, EventArgs e)
{
this.ShowRequestedForm(ApplicationVariables.NextWindowForm);
}

private void ShowRequestedForm(System.Windows.Forms.Form FormToShow)
{
ApplicationVariables.CurrentWindowForm = this;
FormToShow.Show();
ApplicationVariables.CurrentWindowForm.Close();
}

--- END CODE WITHIN INHERITED FORM ---

--- BEGIN CODE WITHIN WINDOWS FORM ---
public partial class HomeForm : VerificationsAssistant.InheritedForm
{
protected override void buttonNext_Click(object sender, EventArgs e)
{
// CODE REMOVED
base.buttonNext_Click(sender, e);
}
}
--- END CODE WITHIN WINDOWS FORM ---

The problem is that when the user clicks the "NEXT" button, any code that is
found within the base.buttonNext_Click event is called twice.

I do not understand why. Any help would be greatly appreciated. Thank you!
 
E

Edwin

Thank you Peter.

I think I understand your reply, but it forces me to ask a question.

If I should not virtualize the base classes click event, what should I do?
If each form I create has a standarized set of steps to be executed
everytime the "Next" button is pressed, what is the right way to do it
without copying and pasting into every "Next" button's click event? Each
form should be able to accept a customized action while at the same time do
its standardized steps.

Is this not a benefit of an Inherted Form?

Thank you for your continued assistance.

Edwin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top