C#でWindowsFormのイベントの発生順番を確認する。

C# コンピュータ
C#

Formオブジェクトを生成する際、各種イベントが発生しますが、その順番を確認したいと思います。

using System;
using System.Windows.Forms;

// コンパイル
// csc /t:exe FormEvent.cs

class Form1 : Form
{
    Form1()
    {
        Console.WriteLine("コンストラクタ");

        Size = new System.Drawing.Size(800,600);

        Activated += (o, e) => { Console.WriteLine("Activated"); };
        AutoSizeChanged += (o, e) => { Console.WriteLine("AutoSizeChanged"); };
        AutoValidateChanged += (o, e) => { Console.WriteLine("AutoValidateChanged"); };
        BackColorChanged += (o, e) => { Console.WriteLine("BackColorChanged"); };
        BackgroundImageChanged += (o, e) => { Console.WriteLine("BackgroundImageChanged"); };
        BackgroundImageLayoutChanged += (o, e) => { Console.WriteLine("BackgroundImageLayoutChanged"); };
        BindingContextChanged += (o, e) => { Console.WriteLine("BindingContextChanged"); };
        CausesValidationChanged += (o, e) => { Console.WriteLine("CausesValidationChanged"); };
        ChangeUICues += (o, e) => { Console.WriteLine("ChangeUICues"); };
        Click += (o, e) => { Console.WriteLine("Click"); };
        ClientSizeChanged += (o, e) => { Console.WriteLine("ClientSizeChanged"); };
        Closed += (o, e) => { Console.WriteLine("Closed"); };
        Closing += (o, e) => { Console.WriteLine("Closing"); };
        ContextMenuChanged += (o, e) => { Console.WriteLine("ContextMenuChanged"); };
        ContextMenuStripChanged += (o, e) => { Console.WriteLine("ContextMenuStripChanged"); };
        ControlAdded += (o, e) => { Console.WriteLine("ControlAdded"); };
        ControlRemoved += (o, e) => { Console.WriteLine("ControlRemoved"); };
        CursorChanged += (o, e) => { Console.WriteLine("CursorChanged"); };
        Deactivate += (o, e) => { Console.WriteLine("Deactivate"); };
        Disposed += (o, e) => { Console.WriteLine("Disposed"); };
        DockChanged += (o, e) => { Console.WriteLine("DockChanged"); };
        DoubleClick += (o, e) => { Console.WriteLine("DoubleClick"); };
        DpiChanged += (o, e) => { Console.WriteLine("DpiChanged"); };
        DpiChangedAfterParent += (o, e) => { Console.WriteLine("DpiChangedAfterParent"); };
        DpiChangedBeforeParent += (o, e) => { Console.WriteLine("DpiChangedBeforeParent"); };
        DragDrop += (o, e) => { Console.WriteLine("DragDrop"); };
        DragEnter += (o, e) => { Console.WriteLine("DragEnter"); };
        DragLeave += (o, e) => { Console.WriteLine("DragLeave"); };
        DragOver += (o, e) => { Console.WriteLine("DragOver"); };
        EnabledChanged += (o, e) => { Console.WriteLine("EnabledChanged"); };
        Enter += (o, e) => { Console.WriteLine("Enter"); };
        FontChanged += (o, e) => { Console.WriteLine("FontChanged"); };
        ForeColorChanged += (o, e) => { Console.WriteLine("ForeColorChanged"); };
        FormClosed += (o, e) => { Console.WriteLine("FormClosed"); };
        FormClosing += (o, e) => { Console.WriteLine("FormClosing"); };
        GiveFeedback += (o, e) => { Console.WriteLine("GiveFeedback"); };
        GotFocus += (o, e) => { Console.WriteLine("GotFocus"); };
        HandleCreated += (o, e) => { Console.WriteLine("HandleCreated"); };
        HandleDestroyed += (o, e) => { Console.WriteLine("HandleDestroyed"); };
        HelpButtonClicked += (o, e) => { Console.WriteLine("HelpButtonClicked"); };
        HelpRequested += (o, e) => { Console.WriteLine("HelpRequested"); };
        ImeModeChanged += (o, e) => { Console.WriteLine("ImeModeChanged"); };
        InputLanguageChanged += (o, e) => { Console.WriteLine("InputLanguageChanged"); };
        InputLanguageChanging += (o, e) => { Console.WriteLine("InputLanguageChanging"); };
        Invalidated += (o, e) => { Console.WriteLine("Invalidated"); };
        KeyDown += (o, e) => { Console.WriteLine("KeyDown"); };
        KeyPress += (o, e) => { Console.WriteLine("KeyPress"); };
        KeyUp += (o, e) => { Console.WriteLine("KeyUp"); };
        Layout += (o, e) => { Console.WriteLine("Layout"); };
        Leave += (o, e) => { Console.WriteLine("Leave"); };
        Load += (o, e) => { Console.WriteLine("Load"); };
        LocationChanged += (o, e) => { Console.WriteLine("LocationChanged"); };
        LostFocus += (o, e) => { Console.WriteLine("LostFocus"); };
        MarginChanged += (o, e) => { Console.WriteLine("MarginChanged"); };
        MaximizedBoundsChanged += (o, e) => { Console.WriteLine("MaximizedBoundsChanged"); };
        MaximumSizeChanged += (o, e) => { Console.WriteLine("MaximumSizeChanged"); };
        MdiChildActivate += (o, e) => { Console.WriteLine("MdiChildActivate"); };
        MenuComplete += (o, e) => { Console.WriteLine("MenuComplete"); };
        MenuStart += (o, e) => { Console.WriteLine("MenuStart"); };
        MinimumSizeChanged += (o, e) => { Console.WriteLine("MinimumSizeChanged"); };
        MouseCaptureChanged += (o, e) => { Console.WriteLine("MouseCaptureChanged"); };
        MouseClick += (o, e) => { Console.WriteLine("MouseClick"); };
        MouseDoubleClick += (o, e) => { Console.WriteLine("MouseDoubleClick"); };
        MouseDown += (o, e) => { Console.WriteLine("MouseDown"); };
        MouseEnter += (o, e) => { Console.WriteLine("MouseEnter"); };
        MouseHover += (o, e) => { Console.WriteLine("MouseHover"); };
        MouseLeave += (o, e) => { Console.WriteLine("MouseLeave"); };
        MouseMove += (o, e) => { Console.WriteLine("MouseMove"); };
        MouseUp += (o, e) => { Console.WriteLine("MouseUp"); };
        MouseWheel += (o, e) => { Console.WriteLine("MouseWheel"); };
        Move += (o, e) => { Console.WriteLine("Move"); };
        PaddingChanged += (o, e) => { Console.WriteLine("PaddingChanged"); };
        Paint += (o, e) => { Console.WriteLine("Paint"); };
        ParentChanged += (o, e) => { Console.WriteLine("ParentChanged"); };
        PreviewKeyDown += (o, e) => { Console.WriteLine("PreviewKeyDown"); };
        QueryAccessibilityHelp += (o, e) => { Console.WriteLine("QueryAccessibilityHelp"); };
        QueryContinueDrag += (o, e) => { Console.WriteLine("QueryContinueDrag"); };
        RegionChanged += (o, e) => { Console.WriteLine("RegionChanged"); };
        Resize += (o, e) => { Console.WriteLine("Resize"); };
        ResizeBegin += (o, e) => { Console.WriteLine("ResizeBegin"); };
        ResizeEnd += (o, e) => { Console.WriteLine("ResizeEnd"); };
        RightToLeftChanged += (o, e) => { Console.WriteLine("RightToLeftChanged"); };
        RightToLeftLayoutChanged += (o, e) => { Console.WriteLine("RightToLeftLayoutChanged"); };
        Scroll += (o, e) => { Console.WriteLine("Scroll"); };
        Shown += (o, e) => { Console.WriteLine("Shown"); };
        SizeChanged += (o, e) => { Console.WriteLine("SizeChanged"); };
        StyleChanged += (o, e) => { Console.WriteLine("StyleChanged"); };
        SystemColorsChanged += (o, e) => { Console.WriteLine("SystemColorsChanged"); };
        TabIndexChanged += (o, e) => { Console.WriteLine("TabIndexChanged"); };
        TabStopChanged += (o, e) => { Console.WriteLine("TabStopChanged"); };
        TextChanged += (o, e) => { Console.WriteLine("TextChanged"); };
        Validated += (o, e) => { Console.WriteLine("Validated"); };
        Validating += (o, e) => { Console.WriteLine("Validating"); };
        VisibleChanged += (o, e) => { Console.WriteLine("VisibleChanged"); };
    }
    [STAThread]
    static void Main()
    {
        Application.Run(new Form1());
    }
}
結果
・起動
コンストラクタ
Move
LocationChanged
HandleCreated
Invalidated
StyleChanged
BindingContextChanged
Load
Layout
VisibleChanged
GotFocus
Activated
Shown
・終了
Closing
FormClosing
Closed
FormClosed
Deactivate
LostFocus
HandleDestroyed
Disposed

コンピュータ
スポンサーリンク
シェアする
八 四をフォローする
スポンサーリンク
迷惑堂本舗

コメント