1. Create a new winform project in Visual Studio.

2. Add in the require control such as textbox, label and buttons.


3. Add two buttons one for the accept button and one for the cancel button.

4. Go to the Form property and scroll down to the Miscellaneous section. In the AcceptButton property set the accept button control. In the CancelButton property select the cancel button control.


AcceptButton: The button click event is triggered whenever the user presses the 'ENTER' key.
CancelButton: The button click event is triggered whenever the user presses the 'ESC' key.

5. In the code behind handle the appropriate events.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using Microsoft.Practices.EnterpriseLibrary.Data;

using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using System.Data.Common;


namespace WinformEnterpriseLibrary


    public partial class Form1 : Form


        public Form1()





        private void Form1_Load(object sender, EventArgs e)




        private void btnAccept_Click(object sender, EventArgs e)


            this.btnAccept.DialogResult = System.Windows.Forms.DialogResult.OK;




        private void btnCancel_Click(object sender, EventArgs e)






* iOS Development * OS X * Product Review