C
Cedric
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
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