Re[4]: Закрытие формы и FormClosingEventArgs
От: Shadow Россия  
Дата: 18.04.16 14:46
Оценка:
Здравствуйте, _Raz_, Вы писали:

_R_>Здравствуйте, Shadow, Вы писали:


S>>Повторюсь, если не нажимать кнопку с неподвешенным обработчиком, то закрытие происходит без вопросов. При нажатии кнопки e.Cancel = true.


_R_>Может тогда дело в Button.DialogResult или Form.CancelButton


Там кода почти нет:
public delegate void BntCancelPressedHandler();

public partial class WaitForm : Form {
public WaitForm() {
InitializeComponent();
ButtonTouched = null;
}

public event BntCancelPressedHandler ButtonTouched;

private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;

if ( ButtonTouched != null)
ButtonTouched();
}
}

ну и код дезигнера

partial class WaitForm {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose( bool disposing ) {
if( disposing && ( components != null ) ) {
components.Dispose();
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support — do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.label1.Location = new System.Drawing.Point(33, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 17);
this.label1.TabIndex = 1;
this.label1.Text = "AVI writing is performed...";
//
// button1
//
this.button1.Location = new System.Drawing.Point(68, 54);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Cancel";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(86, 1);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 3;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// WaitForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(228, 81);
this.ControlBox = false;
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "WaitForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;

}

то есть самая простая форма получается
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.