-
Apr 22nd, 2011, 05:59 AM
#1
Thread Starter
Fanatic Member
Form.show + Single instance.
I have two forms ,
say FormA and FormB
In FormA, a Button Click i wrote FormB.Show.
When i click again the button its creating another instance of FormB.
i want to make FormB as single instane, if again the button event raised i need to focus the FormB rather creating another instance.
Visual Studio.net 2010
If this post is useful, rate it
-
Apr 22nd, 2011, 06:19 AM
#2
Re: Form.show + Single instance.
If all you did was FormB.Show then it's not creating another instance, so either you are incorrect or you aren't telling us everything. The code, as you have shown it, is using the default instance. there's only one default instance so you could only be showing one form. If there are multiple instances then you must be creating multiple instances, something like this:
vb.net Code:
Dim f As New FormB f.Show()
As much as I generally don't like default instances, the singleton-like behaviour that they provide is handy in certain situations and, as that's the behaviour you want, this is a situation where using a default instance is advisable. Assuming that your class is named FormB, this code will display an instance if one isn;t already displayed and focus it if there is:
vb.net Code:
FormB.Show() FormB.Activate()
-
Apr 22nd, 2011, 07:18 AM
#3
Fanatic Member
Re: Form.show + Single instance.
Originally Posted by vijy
I have two forms ,
say FormA and FormB
In FormA, a Button Click i wrote FormB.Show.
When i click again the button its creating another instance of FormB.
i want to make FormB as single instane, if again the button event raised i need to focus the FormB rather creating another instance.
have you made the objects of the forms?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|