Help on forms

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!!!!!





Answer this question

Help on forms

  • Jorge Lalinde

    Yes, but how do you get form B to take on modal-like characteristics   The user will still be able to click on form A and work with it.
  • Capistrc

    (Hallelujiah chorus plays)
    (cries while shaking puzzlehacker's hand)
    Thank you, thanks you, THANK YOU!!!!!!!!!!!

  • Kushal

    private void button1_Click(object sender, System.EventArgs e)
    {
    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

    If you show Form B at the beginning of the Form_load sub, Form A will continue to process your startup work and then you can close Form B within the Form_load sub in Form A before Form A is displayed.


     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

    When you press the button on form a to open form b use ShowDialog() instead of Show().

    HTH

  • higgins427

    The example I gave was referring to was:

    "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

    HOWEVER!!!

    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

  • Help on forms