שתף באמצעות


Form.isLoaded?

Question

Tuesday, August 3, 2010 12:12 AM

Is there a way to check if a form has been loaded yet? I saw in C# they have a isLoaded property, but it doesn't seem to exist in the VB.Net Form class?

All replies (18)

Tuesday, August 3, 2010 12:23 AM ✅Answered | 1 vote

I won't say "no there's not" but if there is, I'm not aware of it.

One thing you might consider doing though is to set a class-level boolean and initialize it to one state, then as the last line in the form's load event, change the state of it.


Tuesday, August 3, 2010 12:41 AM ✅Answered

I was thinking of doing something similar. I was going to dynamically add an event handler for the forms Load event in the New method of the Control - and then when the load event is called set a class level boolean to true. Haven't tried it yet though, but should work :P

 

Just seems kind of dumb that they don't have it built-in.... Another reason VB bugs me >.<


Tuesday, August 3, 2010 12:44 AM

I was thinking of doing something similar. I was going to dynamically add an event handler for the forms Load event in the New method of the Control - and then when the load event is called set a class level boolean to true. Haven't tried it yet though, but should work :P

 

Just seems kind of dumb that they don't have it built-in.... Another reason VB bugs me >.<

Ah ok - One thing to be cautious of though is how long it takes for (whatever's in the form's load event) to fully load.

Good luck with it. :)


Tuesday, August 3, 2010 1:02 AM

Where are you finding this IsLoaded property in C#?  I don't see it.

--
Mike


Tuesday, August 3, 2010 1:07 AM

When the Load Event is raised, the instance of the form is created and( if it is the main form, the message loop is running), but the form has not been painted yet.

So, it is fully functional, but not visible.


Tuesday, August 3, 2010 2:00 AM

There is a Form.Shown event as well as the Form.Load event .Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261


Tuesday, August 3, 2010 2:44 AM

Where are you finding this IsLoaded property in C#?  I don't see it.

--
Mike

WPF controls and form have this property (VB also)


Tuesday, August 3, 2010 2:51 AM

Ah, that explains it.  I never venture into WPF land...

--
Mike


Tuesday, August 3, 2010 6:03 AM

When the Load Event is raised, the instance of the form is created and( if it is the main form, the message loop is running), but the form has not been painted yet.

So, it is fully functional, but not visible.

I'm mostly concerned with whether or not the InitializeComponent Code has run yet. So actually, if it exists, I migth be able to check to see if there is a isInitialized property. I'm trying to get around a serialization issue.

 

Namely, in the designer I want to be able to select a custom element from a custom list and I want it to retain the index information for it (vs serializing the actual instance of the custom element retrieved from the custom list). I had a lot of trouble figuring out how to go about getting my custom list, and of choosing a specific element form the list, to work with the designer properly. I searched all over for a decent book on the topic but found nada >.>. But I've got it pretty much working now, just fixing a couple small bugs.

 

I don't much like that designer - tries to block me at every turn >.>


Tuesday, August 3, 2010 7:00 AM

Iam1Me

C# has no properties, like VB it has keywords, in both do IsLoaded not exist.

Success
Cor


Tuesday, August 3, 2010 4:18 PM

Iam1Me

C# has no properties, like VB it has keywords, in both do IsLoaded not exist.

Success
Cor

  1. Semantics - C# has properties even if the language doesn't explicitly refer to them as such. A rose by any other name.

2) I've seen the C# isLoaded property on this website, somewhere in documentation when I was searching for the VB.NET equivolent. Others have pointed out that it is in the WPF library.


Tuesday, August 3, 2010 4:36 PM

That is not C# that is Net, that is for VB, C# and Managed C++.

If it is for C++ managed in Net then it is for VB and C#

However, everybody can make his own is IsLoaded method

Imports System.Runtime.CompilerServices
Public Class Form1
 Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
  MessageBox.Show(Me.IsLoaded.ToString)
 End Sub
End Class
Module FormExtensions
 <Extension()>
 Public Function IsLoaded(ByVal aForm As Form) As Boolean
  If aForm.IsDisposed = True Then
   Return False
  Else
   Return True
  End If
 End Function
End Module

Success
Cor


Tuesday, August 3, 2010 5:31 PM

 

Cor,

There is also the case where it is not loaded because it was never done

Module FormExtensions
  <Extension()>
  Public Function IsLoaded(ByVal aForm As Form) As Boolean
    If aForm Is Nothing OrElse aForm.IsDisposed = True Then
      Return False
    Else
      Return True
    End If
  End Function
End Module

Tuesday, August 3, 2010 5:55 PM

Crazypennie,

I was afraid of this, I wanted only to show that IsLoaded is not a part of the program languages C# or/and VB.

Nevertheless, thanks, it adds in my idea in fact to this thread.

:-)

Success
Cor


Tuesday, August 3, 2010 8:05 PM

If you want to be technical, none of the functions in the System.Windows.Forms.Form (or most other classes for that matter) are part of the language. They are part of the Library you use.


Thursday, August 5, 2010 7:11 AM

Idea from a beginner: check Me.CanFocus, this is False while Form is loading and True when Form is loaded, if I'am correct.


Thursday, August 5, 2010 9:37 AM

zeehaasje

CanFocus dont work,

If the property "Enabled" of the form/control is set to False the "CanFocus" return False. and this regardless if it is loaded or not

Also, when a form "A" open a form "B" with "ShowDialog(me)", CanFocus does return false for the form "A" even if it is loaded


Friday, July 27, 2012 4:55 PM

Try this.

if Form1.Visible then
   Form1.show
else
   Messagebox.Show("Form1 already opened")
end if