/ / UserControlを閉じるときのイベントは何ですか? - c#、winforms

UserControlを閉じるときのイベントは何ですか? - c#、winforms

私はクラスを継承しています UserControl

public partial class MyView : System.Windows.Forms.UserControl

ユーザーが右上隅のXをクリックしたときに発生するイベントを処理したい。多分それは Form.Closing?しかし、私はデザイナーの選択肢としてそれを見ることはできません。どのようなイベントですか?

編集:

デザイナーが利用できるすべてのイベントのリスト

回答:

回答№1は1
class SomeControl : UserControl
{
Form _owner;

public SomeControl()
{
}

protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);

if (Visible)
{
_owner = FindForm();
//_owner = ParentForm;
_owner.FormClosing += _owner_FormClosing;
_owner.FormClosed += _owner_FormClosed;
}
}

private void _owner_FormClosed(object sender, FormClosedEventArgs e)
{
throw new NotImplementedException();
}

private void _owner_FormClosing(object sender, FormClosingEventArgs e)
{
Hide();
_owner.FormClosing -= _owner_FormClosing;
_owner.FormClosed -= _owner_FormClosed;
Parent.Controls.Remove(this);
_owner = null;
}
}