|
-
May 5th, 2013, 03:45 PM
#1
Thread Starter
New Member
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 !
-
May 5th, 2013, 04:22 PM
#2
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!
-
May 5th, 2013, 05:17 PM
#3
Thread Starter
New Member
Re: How to hide the main form in other way ?
 Originally Posted by dunfiddlin
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)..
-
May 5th, 2013, 05:45 PM
#4
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!
-
May 6th, 2013, 10:30 AM
#5
Thread Starter
New Member
Re: How to hide the main form in other way ?
 Originally Posted by dunfiddlin
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.
-
May 6th, 2013, 11:48 AM
#6
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|