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):
http://ufu.co.il/files/iqpj9dhuxeag29f2mkew.png
The "Login" button perform this:
Code:
Form2.Show()
Me.Hide()
This is how "Form2" looks like:
http://ufu.co.il/files/z70b1947wu8ku5xgrbke.png
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 :blush:
Thanks !
Re: How to hide the main form in other way ?
Quote:
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.
Re: How to hide the main form in other way ?
Quote:
Originally Posted by
dunfiddlin
Yes you can.
Project Menu > Project Properties > Application > ShutDownMode > When last form closes.
Probably my explanation wasn't well :blush:
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)..
Re: How to hide the main form in other way ?
Er ... yes .... after is the only situation to which this setting applies. :confused:
Re: How to hide the main form in other way ?
Quote:
Originally Posted by
dunfiddlin
Er ... yes .... after is the only situation to which this setting applies. :confused:
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:
Quote:
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 ?
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:
Public Class Form1
Dim CanClose As Boolean = False
Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not CanClose Then e.Cancel = True
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
CanClose = True
Me.Close()
End Sub
End Class