Yes, there are several ways to do this. My tip for you is to create a simple form with all the default behaviors for the system’s Forms and whenever you create a new form, make this new one inherit the default form.
public class FormPadrao : Form
{
/* Outros métodos */
private void form_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
}
And the use would look like this
public FormCadastro : FormPadrao { }
If you need it for all the Forms, including those that already exist can simply create a class called Form
. Realize that all the Forms already inherited from a class called Form
, then, from the moment you define a class with this name, the current Forms will inherit the form that was created within your project.
So the Form
pattern would look like this
public class Form : System.Windows.Forms.Form { }
Create a standard form that contains this functionality and all others that are required and inherit all other forms from this.
– Reginaldo Rigo
In case this would be feasible only for the new correct Foms?
– Leo Longhi
@Leolonghi No, if you make the name of this form (class) to be
Form
, This will be worth for those who have already been created too.– Jéf Bueno
@Some way to undo this?
– Leo Longhi
@Leolonghi yes, just click "restore" below it. But it was just a suggestion, see how much better you think. No problem have deleted, it was just an idea.
– Bacco