How to Show Child Forms From VB.net though Menu Click Event

Aiby

Member
Joined
Aug 15, 2005
Messages
12
Location
India
Programming Experience
5-10
I am Started a VB.net Project with Two forms One MDI and Another on with Child. A menu is added in MDI form.

Private Sub SubMenuClassification_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubMenuClassification.Click

frmClassification.Show()

End Sub



This is not working, Error message is :
Referance to a non-shared member requires an Object Referance


 
tomhosking said:
Have you created an instance of the child form?

eg

Public childform As New frmClassification()

No!!

I am very new with Vb.net !!

I tried as i work with VB6

Could you tell me where should i Declare it as Public From!! Please
 
VB.NET:
[size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] SubMenuClassification_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Object[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] SubMenuClassification.Click
   Dim ChildForm As New [/size][size=2]frmClassification
   With ChildForm
	  .MdiParent = Me
	  .Show
   End With
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Su[/color][/size]
 
Is it the standard way to access a child form In VB.net ? ( Instancing the orginal form )
is it the only way to access a child form ?
 
the only way to access and use objects is to have an instance of the object in which to access it by (vb6 does this too) in .net you simply have to create the instance(s) yourself (vb6 just assumed of which that's bad)
 
Instancing form

Thank you..


Ok what is the difference between these

Public childform As New frmClassification()
AND

PrivateSub SubMenuClassification_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles SubMenuClassification.Click
Dim ChildForm As New
frmClassification
With ChildForm
.MdiParent = Me
.Show
End With
EndSu

If i wanna declare it as Public childform As New frmClassification() ..?!
In MDI Forms Declaration ? If i do like that it words for the first time.. but after loading closing the form if Try for the second time it Generates an Error!!!


I would like to know how effectively i can use this !! Thank you all for reply me and to give a good start, Thank you once again
 
Hi,

may b i can help u out with the first part of ur query -

the difference between :

Public childform As New frmClassification()
AND
PrivateSub SubMenuClassification_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles SubMenuClassification.Click
Dim ChildForm As New
frmClassification
With ChildForm
.MdiParent = Me
.Show
End With
EndSu



By using the first one u r declaring the instance(object) of "frmClassification" class as public access.
Doing so permits the access of this object anywhere in the class.

the second one is limiting the access/scope of the object to the block where it is declared.So u will not be able to access the object anywhere else in the class,except in the block of declaration.

If there is more explanation to this plz let me konw.

Cheers
GKG

"Knowledge Grows when imparted"


 
Yes GKG that part can be understand.. but the question is in this case when Some one have to Access a child form From MDI forms menu item! the public declaration works only once.. !! once you close the loaded form and try again it will generate error..


when i tried the second way .. every Menu Selection it generation a new from :( I dont need it to be work like thataaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Ahaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
actually if an object is declared as public it can be accessed anywhere on the system (even other programs)

if you want something to only be accessed anywhere in that program you should declare it as Friend (declaring it as friend means other programs can't see it)

and the reason that the one declared as public only works once is because once it's closed then the object doesnt exist anymore and you have to make a new instance

mine works because whenever the user clicks the button a new instance is made then showed

now if you only want 1 instance of the form then all you've got to do is check to see if an instance is already open or not:

VB.NET:
Friend ChildForm As New frmClassification

Private Sub SubMenuClassification_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles SubMenuClassification.Click
  With ChildForm
	If .Disposed = True Then
	  .MdiParent = Me
	  .Show
	Else
	  .Focus()
	End If
  End With
End Sub
 
Is there any way to know how many Instance of an Object is Created

Thank you JuggalaBrotha,

Its work.

But tell me is there any way to Identify how many instance of an Object have been created or exist ? Do we get a control on a specific intance ? ( By any build in mechanism)

Thank you once again

Aiby...
 
the best way to know how many instances of a particular form is to make an integer variable then whenever you make an instance add one to the variable then in the closed event of the form minus one from that variable
 
:)

Ok ! Then how to Acitivate or Work with specific instance of an Object..!! Is there any Building Mechanism any such count of instances and tracking
 
JuggaloBrotha said:
not that i know of

JuggaloBrotha.. Thank you so much for your interest and support... thank you.. I will post any related information to this Tread as i get any clue.. :) Bye
 
Back
Top