Results 1 to 6 of 6

Thread: How to hide the main form in other way ?

  1. #1

    Thread Starter
    New Member xRedSn0w's Avatar
    Join Date
    May 2013
    Posts
    7

    Question How to hide the main form in other way ?

    Hello VBForum !
    I just registered and it looks like a very awesome forum

    I have a very small question, just started with all the Visual Basic business..
    To make your life easier, I'll demonstrate it hehe

    I made a button in the main form, and 2 textboxes, like that (a simple login screen, which doesn't work yet):



    The "Login" button perform this:

    Code:
    Form2.Show()
    Me.Hide()
    This is how "Form2" looks like:



    The "x" button perform this:

    Code:
    Form1.Show()
    Me.Close()
    And then it shows up "Form1" again.. now, for my question:
    Is there a way to hide the "Form1" or even close it, in order to show it up like the same way "Form2" do ?

    I mean, after you open up "Form2" you only HIDE "Form1", and when you close "Form2" and open it once again, the opening way is different, because it's not only hidden.
    I did this before, but I'm not sure how.. and no, I can't do "Form1.close", because it terminates all the debugging.


    Lol hope you understand
    Thanks !

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to hide the main form in other way ?

    I did this before, but I'm not sure how.. and no, I can't do "Form1.close", because it terminates all the debugging.
    Yes you can.

    Project Menu > Project Properties > Application > ShutDownMode > When last form closes.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    New Member xRedSn0w's Avatar
    Join Date
    May 2013
    Posts
    7

    Re: How to hide the main form in other way ?

    Quote Originally Posted by dunfiddlin View Post
    Yes you can.

    Project Menu > Project Properties > Application > ShutDownMode > When last form closes.
    Probably my explanation wasn't well
    When I said "close the first Form", I meant to close it AFTER I OPEN UP the second form, understand? (same as Me.Close instead of Me.hide)..

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to hide the main form in other way ?

    Er ... yes .... after is the only situation to which this setting applies.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    New Member xRedSn0w's Avatar
    Join Date
    May 2013
    Posts
    7

    Re: How to hide the main form in other way ?

    Quote Originally Posted by dunfiddlin View Post
    Er ... yes .... after is the only situation to which this setting applies.
    Ohh I'm so sorry, I wasn't home so I couldn't try it, so I was thinking that you meant something else..
    Thank you so so much, it works !!!

    Edit: but there is another problem.. after I did what you told me, I changed the Me.Hide to Me.Close and it worked fine,
    but when I tried to prevent a closing of the application (by the X in the top right, or right click on the window's toolbar), in this way:

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
    Dim cp As CreateParams = MyBase.CreateParams
    Const CS_NOCLOSE As Integer = &H200
    cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
    Return cp
    End Get
    'End Property
    The Me.Close get not effect and the other form (Form2) just show up, and Form1 isn't close :S
    how can I combine it? do Me.Close (to Form1), and at the same time prevent it's closing ?
    Last edited by xRedSn0w; May 6th, 2013 at 10:45 AM.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to hide the main form in other way ?

    In the following, the form cannot be closed by any method other than clicking a particular button. You can replace the button with whatever trigger you want ...

    vb.net Code:
    1. Public Class Form1
    2.     Dim CanClose As Boolean = False
    3.  
    4.     Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    5.         If Not CanClose Then e.Cancel = True
    6.     End Sub
    7.  
    8.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    9.         CanClose = True
    10.         Me.Close()
    11.     End Sub
    12. End Class
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

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