|
-
Jan 30th, 2003, 03:20 PM
#1
Thread Starter
Registered User
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.
-
Jan 30th, 2003, 06:31 PM
#2
Hyperactive Member
In Form 1, try:
as the Form might be flipping to the back.
-
Jan 31st, 2003, 11:25 AM
#3
Thread Starter
Registered User
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.
-
Jan 31st, 2003, 12:18 PM
#4
-
Jan 31st, 2003, 01:04 PM
#5
Addicted Member
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
-
Jan 31st, 2003, 02:46 PM
#6
Thread Starter
Registered User
no luck
Well neither of them worked. Here is what I have in my module:
VB Code:
Waiting.ShowMessage("Please Wait...")
Try
Dim hc As New form2()
hc.ShowDialog()
Catch
End Try
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
-
Jan 31st, 2003, 02:54 PM
#7
Frenzied Member
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.
-
Jan 31st, 2003, 03:16 PM
#8
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:
Dim wShowing As Boolean
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Waiting.ShowMessage("Please Wait...")
wShowing = True
End Sub
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
If wShowing Then
wShowing = False
Waiting.HideMessage()
End If
End Sub
-
Jan 31st, 2003, 03:23 PM
#9
If you want to add the IsShowing property then this is how it'd go:
VB Code:
'the code the waiting form
Private Shared _frm As Waiting
Private Shared _IsShowing As Boolean
Public Shared Sub ShowMessage(ByVal msg As String)
_frm = New Waiting()
'set text
_frm.lblMsg.Text = msg
'some resize code should go here to handle lareger text
'put on top like showdialog
_frm.TopMost = True
'show it
_frm.Show()
_IsShowing = True
'make sure it repaints
Application.DoEvents()
End Sub
Public Shared Sub HideMessage()
'close and clean
_frm.Close()
_IsShowing = False
_frm.Dispose()
End Sub
Public Shared ReadOnly Property IsShowing() As Boolean
Get
Return _IsShowing
End Get
End Property
'the code for the form using it or being loaded
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Waiting.ShowMessage("Loading Please Wait...")
End Sub
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
If Waiting.IsShowing Then Waiting.HideMessage()
End Sub
-
Jan 31st, 2003, 03:26 PM
#10
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.
-
Jan 31st, 2003, 04:26 PM
#11
Hyperactive Member
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.
-
Jan 31st, 2003, 08:49 PM
#12
Sleep mode
-
Feb 3rd, 2003, 11:09 AM
#13
Thread Starter
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|