Keeping one form on top of the calling form - vb.net

I'm using VB.NET (VS2008) and have a form (frmMain) that calls another form (frmCleanUp) but when frmCleanUp shows it can be hidden behind frmMain.
What I'd like to have is the new form be locked and have to close to get rid of it?
Thanks..

Show the Form with .ShowDialog() instead of .Show().
This way, the form is shown as modal dialog box and will stay on top until you close it.

when you show the form, do it with ShowDialog
in frmMain do:
frmCleanUp.ShowDialog

Related

Unable to close VBA form

Real simple.
I have excel vba code which launches a form.
I have a close button on the form.
What would be the code to close the form?
Me.close doesn't work.
Indellisense doesn't seem to be giving me the right choice....
Unload Me is what I use. But you dont really need a close button. The user can just click the X in the top right corner.
if you wish to close the whole program then you should use
mainformname.close()
If you want to keep the main form open but hide the new form simply type
me.hide()

Program is running even after the close button pressed

I have a 2 form program,the first form's button click will open the second form when clicked. I tried using a .close() to hide the first form, but that ended the whole program. Then I tried using a .hide(). Now, when I click the X button in the top right of the second form, the program closes, but is still running in the background. How do I get around this?
By default, a VB.NET application will exit when you close the startup form. If you're hiding the startup form and closing the second form then the startup form is still open, so the app won't exit.
If you want to be able to close the first form without exiting the application then go into the project properties and set the shutdown mode to when all forms close instead of when the startup form closes. That way, you can show your second form and then close your first form. Closing the second form will then exit the app.
Simply close the main Form from inside the second form's FormClosed event.
Sub Form2_FormClosed(sender As Object, e As FormClosedEventArgs)
Form1.Close()
End Sub
You should use Me.Close() just before the ShowDialog() function for the second window.
if you want the 1st form to be visible again, add a form1.show() to the form_closing event of the 2nd form
if you want the program to end, add an Application.Exit to the form_closing event of the 2nd form

Suggestion window in mdi form

I have a problem stated below....
I have a MDI form having different child form. if i open the form then if related data not exist in database, a suggestion banner should appear top of the forms to enter related data first. Even, if I close the child form, suggestion banner should remain open and Onclick on that banner go to specific form to add the record. There should be different banner of different forms. so please help me to implement this scenario.
Thanks in Advance.
I want to use which control as banner. so after struggling i fount panel best as banner. Setting panel property -> AccessibleRole = Alert. So I implement scenario easily.
Instead of opening the child form, open the banner form first (which opens the child form).
Then check in the banner form if the data has been entered. If it has:- close the banner form.

Total focus on a Form: ignore all others

in my VB.NET application, my main Form can show other Forms. That works fine, but I need to set "focus" on the newly opened form, and don't allow the user use the main form until the opened Form is closed. How do I do that?
The Form.ShowDialog() method shows a form as a dialog box; this should keep the focus on that form until it is closed (by the user or your code).
Use the Form.ShowDialog() method.
It will show you the form as a dialog box, so focusing is at total, and it will ignore all other forms or objects.

Closing forms in VB.NET

I have a small requirement and that is as follows:
I have a login form and after a successful login, i open another MDI form, but i want to close the login form. I have given the code as:
MDIForm1.show
Me.Close
This does not seem to work.
Can anyone help on this.
Similarly, is is possible to open the login form on an inactive MDI form [MDI and Login for to be seen] and when th user login details are correct, it must close the login form and return to the MDI Form.
Please help on this.
Regards,
George
Firstly, I'm guessing you've set your login form as the application's startup form? If so then VB has put something like this together for you behind the scenes:
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New LoginForm)
The magic happens there in that Application.Run call, which basically creates a message loop for your GUI and terminates when it detects that your form has been closed.
There are a couple of ways that I know of to deal with this.
First: don't make the login form your startup form at all. Create your main form, but cause it to hide itself and ShowDialog on an instance of your login form before appearing.
Make your login form your startup object, but instead of closing it when you open your main form, simply hide it (this is actually pretty horrendous to me personally, but it's a possibility).
As for the MDI form question: this seems completely possible to me, if I understand you correctly. You want to show both the login form and the MDI form at once, but you want the MDI form to be disabled until the login form is closed, right?
So just make the MDI form your application's startup form, have it call ShowDialog on your login form in its Load event, and bingo: the MDI form will effectively be "locked" until the login form is dealt with (this is how modal dialogs in general such as MessageBox work). This is actually the same as option #1 above except that the main form (your MDI form) is never hidden, only blocked.
Other ways:
Dim <form name> As New <form name>
<form name>.Show()
Me.Hide()