VB.NET overload default functionality when user clicks the X (Close Program)

后端 未结 3 561
时光说笑
时光说笑 2021-01-15 10:04

How do I go about overriding the default functionality when a user clicks the X in a VB.NET form-based application?

I am currently handling the MyBase.Closing event.

3条回答
  •  佛祖请我去吃肉
    2021-01-15 10:22

    Re your other comments; doing anything before the event has fired would be premature; after all, some other code might cancel the close, and you'd be left with a scuppered form. Personally, I'd be tempted to override OnClosed; not much of a VB head, but in C#:

        protected override void OnClosing(CancelEventArgs e)
        {
            // check OK to close (save/cancel etc)
            base.OnClosing(e);
        }
        protected override void OnClosed(EventArgs e)
        {
            // your code here
            base.OnClosed(e);
            // or here
        }
    

提交回复
热议问题