Results 1 to 3 of 3

Thread: Form.show + Single instance.

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    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


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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:
    1. Dim f As New FormB
    2.  
    3. 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:
    1. FormB.Show()
    2. FormB.Activate()

  3. #3
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: Form.show + Single instance.

    Quote Originally Posted by vijy View Post
    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
  •  



Click Here to Expand Forum to Full Width