Default form instances in VS2005

  • Thread starter Thread starter Oenone
  • Start date Start date
O

Oenone

I'm sure I read some time back that in VB 2005, MS were re-introducing the
concept of default form instances, so that if I have a form named MyForm I
can simply call MyForm.Show without having to explicitly declare an instance
of the form.

Did this make it into the final release? And if so, how do I use it?
Attempting to show a form based on its class name gives me the following
error (which is what I would expect if this feature were not present):

"Reference to a non-shared member requires an object reference."

Thanks,
 
I haven't tried yet (still with VS 2003), but I think I read it was
something like

My.Forms.MyForm.Show()

Hope it helps
 
Oenone said:
I'm sure I read some time back that in VB 2005, MS were re-introducing the
concept of default form instances, so that if I have a form named MyForm I
can simply call MyForm.Show without having to explicitly declare an instance
of the form.

Yes, because the ?10 years since VB *4* made forms proper objects
clearly hasn't been enough time for it to sink in...
Did this make it into the final release? And if so, how do I use it?
Attempting to show a form based on its class name gives me the following
error (which is what I would expect if this feature were not present):

"Reference to a non-shared member requires an object reference."

As far as I know this is in (no 2005 on this machine so can't check).
The example code can be found at
<http://msdn2.microsoft.com/library/1fsza1t2.aspx> But really, why?
 
Larry said:
Yes, because the ?10 years since VB *4* made forms proper objects
clearly hasn't been enough time for it to sink in...

You don't need to convince me, I'd much prefer not to access forms like
this. But I'm trying to write an upgrade application which will get code
from VB6 (which has already been pushed through the VS2005 upgrade wizard,
and which is using default form instances) running in VB.NET2005 with as
little manual intervention as possible.
As far as I know this is in (no 2005 on this machine so can't check).
The example code can be found at
<http://msdn2.microsoft.com/library/1fsza1t2.aspx>

Thanks for this -- this tells me that I should be able to simply call
MyForm.ShowDialog(). I've tested this in a separate application and it works
fine. But all the forms I've upgraded from VB6 are still failing with the
error from my original post.

Guess I'll have to spend some time working out what's different between a
new form added directly in VS2005, and an old form upgraded from VB6.

Thanks for your help,
 
Oenone said:
Guess I'll have to spend some time working out what's different
between a new form added directly in VS2005, and an old form upgraded
from VB6.

Ah, I found the difference.

You can only use default form instances if the Application type is Windows
Application. If it's set to Class Library (as mine is), the default
instances all stop working. Gah!
 
Oenone said:
I'm sure I read some time back that in VB 2005, MS were re-introducing the
concept of default form instances, so that if I have a form named MyForm I
can simply call MyForm.Show without having to explicitly declare an
instance of the form.

Did this make it into the final release? And if so, how do I use it?
Attempting to show a form based on its class name gives me the following
error (which is what I would expect if this feature were not present):

"Reference to a non-shared member requires an object reference."

I do not have the final yet, but I would /never/ use the syntax '<class
name>.<instance member>'. I suggest to use 'My.Forms.<class name>.<instance
member>' instead.
 
There really should be the ability to disable this feature. I understand
the reasons for putting it in but being able to disable could be used to
stop newer members of my team that are still trying to use it.
 
Oenone said:
I'm sure I read some time back that in VB 2005, MS were re-introducing the
concept of default form instances, so that if I have a form named MyForm I
can simply call MyForm.Show without having to explicitly declare an instance
of the form.

Did this make it into the final release? And if so, how do I use it?
Attempting to show a form based on its class name gives me the following
error (which is what I would expect if this feature were not present):

"Reference to a non-shared member requires an object reference."

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top