Hallo!
I needs some help.
I have two forms, the first one we will call "sdfjkgfwerngihfdnkgenm", the second one we will call "sdfjkgfwerugihfdnkgenm". Got it
LOL
No, a and b.
Now, form "a" starts up, you press a button on it and then form "b" starts. NOW,
How do I make it so that, form "a" cannot be accessed until form "b" is closed
- TopLevel and TopMost do NOT prevent user activity on form "a", when assigned to form "b"
PLEASE HELP!
Thanks!!!!!

Help on forms
Jorge Lalinde
Capistrc
(cries while shaking puzzlehacker's hand)
Thank you, thanks you, THANK YOU!!!!!!!!!!!
Kushal
{
this.Enabled = false;
Form2 frm = new Form2();
frm.Closed += new EventHandler(frm_Closed);
frm.Show();
}
private void frm_Closed(object sender, EventArgs e)
{
this.Enabled = true;
MessageBox.Show("Form Closed");
}
mcmcom
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frmB As Windows.Forms.Form
frmB = New Form2
frmB.Text = "Form B"
frmB.Show()
'Do your startup work here.
frmB.Dispose()
End Sub
spb622
HTH
higgins427
"I want to open Form B (a splash screen) from Form A (my main form which takes a while to load) and continue processing all those things I need to do at startup and eventually close Form B from Form A."
Form A would not be visible until all of the startup work was completed and Form B was disposed of. So the user would not have the ability to do anything with Form A while the startup work was being done.
Here is what I came up with to answer your question:
Form1
Put two buttons on Form1
Code for Button1:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frmB As New Form2
Dim iCount As Integer
frmB.Text = "Form b"
g_blnIsModal = True
frmB.Show()
For iCount = 1 To 1000000
Application.DoEvents()
Next
MsgBox("Finished")
frmB.Dispose()
End Sub
Code for Button2:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("Clicked", MsgBoxStyle.OKOnly)
End Sub
Code for Form2:
Private Sub Form2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus
If g_blnIsModal Then
Me.Focus()
End If
End Sub
Code for module1:
Module Module1
Public g_blnIsModal As Boolean
End Module
If you run this code and click on Button1 on Form1, Form2 will be displayed and if you click on Button2 on Form1 the focus will be set back to Form2.
This will not allow the user to interact with Form1 until the work from Button1 on Form1 has completed.
What I did notice is that when you click on Form1 the title bar turns blue but doesn't turn gray again when the focus is returned to Form2. If you drag Form2 over the title bar of Form1, the part that Form2 covered will be gray, but the rest will still be blue.
batman900
This does not allow me to continue doing useful work on Form A after opening Form B. Granted, most of the time ShowDialog() (a blocking call) is what we want, but what about those cases when this is not what we want
I want to open Form B (a splash screen) from Form A (my main form which takes a while to load) and continue processing all those things I need to do at startup and eventually close Form B from Form A. If I call ShowDialog(), Form A can no longer continue loading. Form B could take over, but the splash screen shouldn't need to be responsible for loading. I've tried spinning off a second thread, but ShowDialog() does make Form B modal to Form A if they are on different threads, and of course I can't spin off the worker thread after making the blocking call.
The only method I've found to create a modal window without blocking is to call into the Windows API EnableWindow(...) function to (ironically) disable Form A and subsequently show Form B using the Show() method. When Form B closes, I call EnableWindow(...) to reenable Form A. Is there any way to accomplish this task within the .NET framework