(VS2005, .Net 2.0)
I have a form that is displayed as a dialog using the ShowDialog() method. The form's CancelButton property is set to a button on the form. Even if I set that button's DialogResult to None, clicking the button still closes the dialog. I don't want this to happen - I want to be able to control whether the dialog closes or not.
This issue doesn't occur with the form's AcceptButton - with that button's DialogResult set to none, I can do what processing is necessary, then decide whether or not to manually set the form's DialogResult to cause it to close.
I thought the CancelButton property was meant soley to indicate the button that should be "clicked" if Escape is pressed (much as the AcceptButton is only supposed to indicate the button to "click" when Enter is pressed). Am I wrong in this? Have I missed some other reason my form is closing? Or is this a bug?
Edit: Code added. This is the dialog form (form 2) with the cancel button (button 1). The cancel button is only the form's CancelButton, it does not have DialogResult set to Cancel, but pressing the button still closes the form
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Name = "button1";
this.button1.Text = "button1";
//
// Form2
//
this.CancelButton = this.button1;
this.Controls.Add( this.button1 );
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout( false );
}