Error when creating panel at run time

prakash77

Active member
Joined
Mar 12, 2010
Messages
29
Programming Experience
Beginner
hi friends, pls help me, when i want to create a new panel at run time when i clicked a radio button it displays an exception at panel2.location...... whats wrong with my program ??

Dim panel2 As Panel
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged

panel2.Visible = True
panel2.Location = New Point(200, 300)
panel2.Size = New Size(200, 300)
Me.Controls.Add(panel2)
 
I think, the problem is, that you declare the Type of Object (Panel), but you have forgotten to create an instance of it.

Suggest to change it like this:

VB.NET:
Dim panel2 As Panel
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
[B]if Panel2 is nothing then Panel2=new Panel[/B]
panel2.Visible = True
panel2.Location = New Point(200, 300)
panel2.Size = New Size(200, 300)
Me.Controls.Add(panel2)
....
 
i got result....

thanks...martin..i got t result.... i made a mistake that i missed new keyword when i m creating my panel...so that i got exception............. thanks for reply martin...
 
Back
Top