LoginSignup
10
8

More than 5 years have passed since last update.

UserControl の後処理(Dispose)

Last updated at Posted at 2017-02-25

概要

.NET Framework でコンポーネントを分離することのできる UserControl は、FormFormClosed/FormClosing にあたるイベントがありません。

ただしスーパークラスの ComponentDisposed イベントが実装されているので、これにイベントを追加する形で後処理を行います。

サンプル

SampleUserControl.cs
using System;
using System.Windows.Forms;

namespace Sample
{
    public partial class SampleUserControl: UserControl
    {
        // コンストラクタ
        public SampleUserControl()
        {
            InitializeComponent();

            /* 初期化処理など */

            this.Disposed += (sender, args) =>
            {
                //
                // ここに後処理を記述
                //
            };
        }
    }
}

注記

  • ControlRemovedという、それっぽい名前のイベントがありましたが、フォームの終了時には呼ばれていないようでした。

参考

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8