Results 1 to 5 of 5

Thread: Close Form

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Location
    Amsterdam, Holland
    Posts
    36

    Exclamation Close Form

    Hi All,

    I created a sub form and in the procedure "Public Sub New()" I'll do some checks.
    If the checks are ok the form will be visible, if not, how do I close the window without any error messages and return back to the main form.

    Thanks,
    AXH

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Close Form

    Quote Originally Posted by ahollaar
    Hi All,

    I created a sub form and in the procedure "Public Sub New()" I'll do some checks.
    If the checks are ok the form will be visible, if not, how do I close the window without any error messages and return back to the main form.

    Thanks,
    AXH
    Hi,

    Try this;

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Me.Close()
    3.     End Sub

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2003
    Location
    Amsterdam, Holland
    Posts
    36

    Re: Close Form

    The window isn't visible yet.
    I want to close the window before it will be visible

  4. #4
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: Close Form

    Hi,

    Just on the new event

    call the me.close or me.dispose method (as you need)

    Hope this helps

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Close Form

    The constructor has nothing whatsoever to do with the form becoming visible. It doesn't make the form visible and it can't the form becoming visible. Once the constructor has completed its then up to the creator whether to call Show or not, which is how the form becomes visible. if your form doesn't want to be shown then it needs to tell its creator not to show it. The most logical way to do this would be to provide a public, read-only, boolean property that indicates whether the checks you performed in the constructor were successful or not, e.g.
    VB Code:
    1. Private ReadOnly _initialised As Boolean = False
    2.  
    3. Public ReadOnly Property Initialise() As Boolean
    4.     Get
    5.         Return Me._initialised
    6.     End Get
    7. End Property
    8.  
    9. Public Sub New()
    10.     '...
    11.  
    12.     'For example.
    13.     Me._initialised = IO.File.Exists("some critical file")
    14. End Sub
    Your main form would create an instance and then check its Initialised property, only showing the form if it was True.

    Having said that, it would be preferable to perform the checks in the main form before even creating the form instance if that's practical. Why create a form if you're never going to use it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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