Results 1 to 13 of 13

Thread: Problem with hiding forms [resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52

    Problem with hiding forms [resolved]

    I have 2 forms and a module. Form1 basically displays "waiting..." so the user knows the program is loading the information on form2 The module has the code:
    Code:
    Dim x as new form1
    x.show()
    dim y as new form2
    y.showdialog()
    In the form_load for form2 I have the following code:
    Code:
    form1.activeform.activate()
    form1.activeform.hide()
    What happens is that when form2 finally loads it flashes up and then closes right away. Any ideas? I thought this had worked before for me and the logic seems right. Maybe I just missing something simple, but that's where your help comes in. Thanks!
    Last edited by shootsnlad; Feb 3rd, 2003 at 04:35 PM.

  2. #2
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    In Form 1, try:
    VB Code:
    1. Me.BringToFront
    as the Form might be flipping to the back.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    Nope, no luck there either. Is it because I do a activeform on form1 from form2 and then hide it? As I understand after the module passes to form1, if you do something to form1 it will affect the entire program. That's why I use the showdialog() option for form2, so the program will stay open even though the initial form gets hidden/closed. Any ideas? The wierd thing is if I run this program on my own, it stays open. If I call it out of another program (which is what I want to happen), it flashes and closes. Any ideas? Thanks for the help.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try this.

  5. #5
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203

    Lightbulb

    try this code:


    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    Form1.ActiveForm.Visible = False
    Dim myform2 As New Form2()
    myform2.Show()
    End Sub

  6. #6

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52

    no luck

    Well neither of them worked. Here is what I have in my module:
    VB Code:
    1. Waiting.ShowMessage("Please Wait...")
    2.             Try
    3.                 Dim hc As New form2()
    4.                 hc.ShowDialog()
    5.             Catch
    6.             End Try
    7.             Waiting.HideMessage()

    When I put in hc.showdialog, it looks as though waiting.hidemessage never gets executed because the 'waiting' stays on the screen along with form2. If I use hc.show, then as soon as the form loads, it closes the program down.

    As far as programmerJon's code, the problem with that is that it will work, but the "loading" doesn't appear, it just sits there with nothing on the screen and eventually form2 loads. That would defeat the point of me being able to tell the user that the program is actually loading.

    Thanks for the suggestions so far, anything else?

    shootsnlad

  7. #7
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    um

    try instancing your forms in a module before you use them and as long as you only need one at a time you will have no problems if you need more than one instance of a form at a time use a collection to orginize your forms. if you search on my name an example of a forms collection will come up

    that whole activeform bit does not work.

    sorry i can't help more but i just happen to be on a machine with net today so i thought i would drop in here
    Magiaus

    If I helped give me some points.

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    SO you want the waiting to go away when the other form is finished loading?

    Since you show it modally then it wont hide until its closed the way you have it. I would use the Load and Activate events in the form that is loading. You'll also need to either add a showing property to the waiting form or just use a boolean in the form that is being loaded.

    VB Code:
    1. Dim wShowing As Boolean
    2.  
    3.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Waiting.ShowMessage("Please Wait...")
    5.         wShowing = True
    6.     End Sub
    7.  
    8.     Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    9.         If wShowing Then
    10.             wShowing = False
    11.             Waiting.HideMessage()
    12.         End If
    13.     End Sub

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If you want to add the IsShowing property then this is how it'd go:
    VB Code:
    1. 'the code the waiting form
    2.     Private Shared _frm As Waiting
    3.     Private Shared _IsShowing As Boolean
    4.  
    5.     Public Shared Sub ShowMessage(ByVal msg As String)
    6.         _frm = New Waiting()
    7.         'set text
    8.         _frm.lblMsg.Text = msg
    9.         'some resize code should go here to handle lareger text
    10.         'put on top like showdialog
    11.         _frm.TopMost = True
    12.         'show it
    13.         _frm.Show()
    14.         _IsShowing = True
    15.         'make sure it repaints
    16.         Application.DoEvents()
    17.     End Sub
    18.  
    19.     Public Shared Sub HideMessage()
    20.         'close and clean
    21.         _frm.Close()
    22.         _IsShowing = False
    23.         _frm.Dispose()
    24.     End Sub
    25.  
    26.     Public Shared ReadOnly Property IsShowing() As Boolean
    27.         Get
    28.             Return _IsShowing
    29.         End Get
    30.     End Property
    31.  
    32. 'the code for the form using it or being loaded
    33.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    34.         Waiting.ShowMessage("Loading Please Wait...")
    35.     End Sub
    36.  
    37.     Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    38.         If Waiting.IsShowing Then Waiting.HideMessage()
    39.     End Sub

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    As a side note .NET can show animated gifs so if you wanted to be fancy you could make or get an animated gif and stick it on the waiting form for a little better look.

  11. #11
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    As a side note .NET can show animated gifs so if you wanted to be fancy you could make or get an animated gif and stick it on the waiting form for a little better look.
    Yeah, just look at the Quick Tips pop-up Form in my VBCodeBook.NET program.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    As a side note .NET can show animated gifs so if you wanted to be fancy you could make or get an animated gif and stick it on the waiting form for a little better look.
    Well , this Pirate's style and without flashes of course .
    Attached Files Attached Files

  13. #13

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52

    solved

    That worked. It now loads as it should. Thanks for the help once again!

    shootsnlad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width