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 forms and whenever you create a new form, make this new 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 this for all forms , including those that already exist, you can simply create a class called Form
. Note that all current forms already inherit from a class called Form
, so from the moment you define a class with this name, the current forms will inherit the form that was created within your project.
Then, the default%% would look like this
public class Form : System.Windows.Forms.Form { }