VB.NET Me.Close() doesn't work, the form doesn't close?

25,415

I am betting the event handler for the button1_click event has been inadvertently removed.

Try double-clicking on the button in design time and see if it pulls you back to that same exact piece of code - or a new event handler definition.

If it's a new event handler definition - copy your code there and delete the first one.

There are other ways to manually add the event handler in the designer's code-behind - but maybe that's for a later progression.

From within VS click the "Show all files" button in solutions explorer. Grab us the code in .Designer.vb and paste it in here and we'll nail it down for you definitively.

Here's mine:


    Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
     _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
     _
    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(131, 91)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(133, 50)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button

End Class
Share:
25,415
Scott
Author by

Scott

Updated on November 19, 2022

Comments

  • Scott
    Scott over 1 year

    The form is an About Us form so has nothing on it only a text box and a OK button.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Me.Close()
    End Sub
    

    Here is how I'm opening the form:

    Private Sub AboutAppStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutAppStripMenuItem.Click
        Dim formAbout As New FormAbout()
        formAbout.Show()
    End Sub
    

    Why won't the button close the form? I'm puzzled, I tried another button just in case with the same result.

    UPDATE: I set a break point on Me.Close() and it isn't reaching it when I click the button, I created a new button and the same thing happened.

    Thanks

    • mrnakumar
      mrnakumar about 15 years
      what code is after formabout.show?
    • Scott
      Scott about 15 years
      Edited to show there is no code after formabout.show.
    • Jeff Olson
      Jeff Olson about 15 years
      Did you perhaps change the name from button1 ? That would break the event wiring...
  • mrnakumar
    mrnakumar about 15 years
    handle keyword is in question above