How can i close my Form
-
button on the control box. i.e validation event is fired and form is not closed Form Causesvalidation property aslo set flase. if i write the code in the Form1_closing event then also the problem is not being solved. This is because the validation event of the textboxes is fired first so the execution never reaches the Form1_closing event. How can i close my Form when user user click [X] button on the control box. or button1??????????????????:eek:
-
button on the control box. i.e validation event is fired and form is not closed Form Causesvalidation property aslo set flase. if i write the code in the Form1_closing event then also the problem is not being solved. This is because the validation event of the textboxes is fired first so the execution never reaches the Form1_closing event. How can i close my Form when user user click [X] button on the control box. or button1??????????????????:eek:
You can override the form close event. and can give your own event handler. So what you can do is ,set e.Cancel=false inside the overrided handler. eg:
protected override void OnClosing(CancelEventArgs e) { try { if(MessageBox.Show("This Will Close Your Form . Do You Want To Continue ?","Conformation",MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.No) { e.Cancel = true; base.OnClosing (e); } else { this.Dispose(); } } catch(Exception Ex) { MessageBox.Show("Ex.Message.ToString(),"Information",MessageBoxButtons.OK,MessageBoxIcon.Information); } }
Sreejith Nair [ My Articles ] -
You can override the form close event. and can give your own event handler. So what you can do is ,set e.Cancel=false inside the overrided handler. eg:
protected override void OnClosing(CancelEventArgs e) { try { if(MessageBox.Show("This Will Close Your Form . Do You Want To Continue ?","Conformation",MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.No) { e.Cancel = true; base.OnClosing (e); } else { this.Dispose(); } } catch(Exception Ex) { MessageBox.Show("Ex.Message.ToString(),"Information",MessageBoxButtons.OK,MessageBoxIcon.Information); } }
Sreejith Nair [ My Articles ]