Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:45:48+00:00 2026-06-13T20:45:48+00:00

I wish in my code to handle the case when the red X at

  • 0

I wish in my code to handle the case when the red X at the upper right of the form is clicked. To this end I consulted this and created an event handler thus:-

Private Sub DoFoo (sender As System.Object, e As System.EventArgs) _
                   Handles Me.FormClosing
    ' Do things
End Sub

but I have found (from setting breakpoints) that on certain forms this event handler is not invoked when the red X is clicked, whereas on others it is. The forms are all of type System.Windows.Forms.Form but naturally are different in most respects. Does anyone know what might be causing this and what to do about it?

Edit

In answer to Vitor’s question, the form that isn’t working is created thus:-

If my_form Is Nothing Then
    my_form = New MyForm(parameters)
    my_form.Title = "Contour Plot Options"
Else
    my_form.BringToFront
End If

my_form.Show

Those that are behaving as expected are created like this:-

If my_working_form Is Nothing Then
    my_working_form = New MyWorkingForm
End If

my_working_form.Show

I can’t see any Visible property to set or clear anywhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:45:49+00:00Added an answer on June 13, 2026 at 8:45 pm

    Your parameters aren’t quite right. A FormClosing event has a FormClosingEventArgs argument:

    Private Sub DoFoo(ByVal sender As Object, ByVal e As FormClosingEventArgs) _
                      Handles Me.FormClosing
        If (e.CloseReason = CloseReason.UserClosing) Then
    
        End If
    End Sub
    

    You can inspect the e variable for the property `CloseReason’, which would include a UserClosing enum, which means the user closed the form.

    Each form should handle its own FormClosing event. Instead of subscribing to the event, I find it better to just override it like this:

    Protected Overrides Sub OnFormClosing(ByVal e As FormClosingEventArgs)
      If (e.CloseReason = CloseReason.UserClosing) Then
    
      End If
      MyBase.OnFormClosing(e)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've came across this use case: Multiple template files have their own JavaScript code
Consider this use case scenario: I wish to auto complete and provide the skeleton
I wish to code a little service where I will be able to send
I wish to improve my code and file structure in larger Win32 projects with
I wish to clear the entire second level cache in NHibernate via code. Is
I wish to have an If statement in my code, which tests if any
I wish upload a video on dailymotion with c# code , but dailymotion doesn't
I am a java devloper and I wish to convert following code to java
I wish to do this using only XAML - How to add an additional
I would love some help on a particular design. This is the code I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.