|
-
March 1st, 2006, 09:41 PM
#1
How to check if a form is visible,without invoking form_load
Is there any straightforward way from keeping form_load from being invoked, when refernecing Form.visible?
I was surprized to find out that form_load() gets called if the form was never shown, and I check form.visible.
-
March 2nd, 2006, 01:52 AM
#2
Re: How to check if a form is visible,without invoking form_load
Hi,
Check for the previous instance of the application.
Thanks
-
March 2nd, 2006, 03:51 AM
#3
Re: How to check if a form is visible,without invoking form_load
Who said he was calling the app again?
If you don't want code to fire, but it in Form_Activate, but include a flag that checks whether Form_Visible is True before it fires..
I hide forms that I'll need again, but only clear all the variables if a pending calculation isn't needed. The pending calc sets the flag.
If it doesn't need to display a total, _Activate sets the form to all zeroes. If it is a total, then the code doesn't fire.
-
March 2nd, 2006, 03:51 AM
#4
Re: How to check if a form is visible,without invoking form_load
The first thing I thought of is If Not Form1 Is Nothing Then... but oddly it isn't ever Nothing, even after setting it to Nothing. I've been using Set Form1 = Nothing when I want to get a form to completely release memory, because there have been cases where variables wouldn't return to the default state. Since that seems to work it made sense that the form would be Nothing, but apparently not. So I guess I'm gonna have to reinvestigate that.
Well, I suppose you could have a Boolean for each form in a module that gets set when the form loads and unloads.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
March 2nd, 2006, 04:02 AM
#5
Re: How to check if a form is visible,without invoking form_load
If you refer to a Form, then it will be loaded into memory, even if it wasn't.
That causes problems if you try to unload a form, and then refer to it again.
It gets loaded again.
-
March 2nd, 2006, 12:25 PM
#6
Re: How to check if a form is visible,without invoking form_load
One thing you can do is to browse the forms collection and see if your form is loaded, if it is loaded, then you can check the visible property. Another option would be to create your form with variables, for example, instead of calling "form2.show", you create a variable "private frm2 as form2" for example. That way, you will have more control on the form (you will be able to set it to nothing That way, you can easily set the variable to "nothing" when it is unloaded.
JeffB
-
March 2nd, 2006, 03:18 PM
#7
Re: How to check if a form is visible,without invoking form_load
Hey Guys !
I think its totally easy in most cases.
do the following
Code:
Private Function IsLoaded(sFormName as string) as Boolean
Dim oForm as Form
For each oForm in Forms
If oForm.Name = sFormName then
IsLoaded = True
exit Function
End if
Next
End Function
This way you find out if a defined form is loaded
wich is very useful in many cases. If you have more Forms with the same name then you can add them a number property ( or using the Tag Property ) too and checking for that numer also
Code:
Private Function IsLoaded(sFormName as string, lgIndex as long) as Boolean
Dim oForm as Form
For each oForm in Forms
If oForm.Name = sFormName then
If oForm.Tag = lgIndex then
IsLoaded = True
exit Function
End if
End if
Next
End Function
so its not needed to load a form to check for Visible
Code:
Private Function IsVisible(sFormName as string) as Boolean
Dim oForm as Form
For each oForm in Forms
If oForm.Name = sFormName then
If oForm.Visible = True then
IsVisible = True
exit Function
End if
End if
Next
End Function
Hope this helps
Jonny Poet
Last edited by JonnyPoet; March 2nd, 2006 at 03:24 PM.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
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
|