By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,557 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,557 IT Pros & Developers. It's quick & easy.

Bug on closing form

P: n/a
Hello,

I have a form that could be closed by a code keyed or selected in a combobox
but when I select my code my program end up with an error
(NullReferenceException) and not when I keying the code.
So Does anybody have an explanation ?

Here is a sample to try :
START CLASS :
Public Class Class1

Shared Sub Main()

Application.Run(New Form1)

End Sub

End Class

FORM CLASS :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.Items.AddRange(New Object() {"EXIT"})
Me.ComboBox1.Location = New System.Drawing.Point(8, 16)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(112, 21)
Me.ComboBox1.TabIndex = 0
Me.ComboBox1.Text = "ComboBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.ComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox1.TextChanged
If ComboBox1.Text = "EXIT" Then
Me.Close()
End If
End Sub
End Class
Select EXIT in Combobox -> Closing with Error

Keying EXIT in Combobox -> Closing with no error
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

If you use Application.Exit() you should have no problem. The only thing I
can figure is that after you call the close method the app is still firing
events, maybe mouse up or something. Hopefully someone else can explain
this. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Cedric" <ce**********@cnv.fr> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have a form that could be closed by a code keyed or selected in a combobox but when I select my code my program end up with an error
(NullReferenceException) and not when I keying the code.
So Does anybody have an explanation ?

Here is a sample to try :
START CLASS :
Public Class Class1

Shared Sub Main()

Application.Run(New Form1)

End Sub

End Class

FORM CLASS :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.Items.AddRange(New Object() {"EXIT"})
Me.ComboBox1.Location = New System.Drawing.Point(8, 16)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(112, 21)
Me.ComboBox1.TabIndex = 0
Me.ComboBox1.Text = "ComboBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.ComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox1.TextChanged
If ComboBox1.Text = "EXIT" Then
Me.Close()
End If
End Sub
End Class
Select EXIT in Combobox -> Closing with Error

Keying EXIT in Combobox -> Closing with no error

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.