views:

63

answers:

2

I need to check if a c# WinForm Window (FORM Class) has been initialized and waiting for user events. But I could not find out how to manage that.

Therefore I had the idea to set the Control.IsAccessible Flag of the Form to true, within the OnLoad Event of the Windows Form.

My question is now, what is the Control.IsAccessible Flag origin intended for? Or is there an other solution to check if the Winform is initialized.

Thanks for your help

A: 

I do not know what IsAccessible is intended for but for the check you are doing you want Created

if(myForm.Created)
{
    //Do stuff
}

I had a whole bunch of problems with it, here is one of my old question on SO that helped me out a lot with it.

Scott Chamberlain
Hey cool. I'm going to make some tests with it, but at the first look it seems to be exactly the thing I was looking for. Thx
BitKFu
Thx for the hint - Created seems to work quite well.
BitKFu
+1  A: 

Control.IsAccessible just means the control is visible to accessibility applications.

You can check myForm.Created to see if the window exists.

You can also register an event handler for the Application.Idle event, which occurs when the application has finished initializing and is ready to begin processing windows messages.

Here is a common usage:

public int Main(string[] args)
{
    Application.Idle += WaitUntilInitialized;
}

private void WaitUntilInitialized(object source, EventArgs e)
{
    // Avoid processing this method twice
    Application.Idle -= WaitUntilInitialized;

    // At this point, the UI is visible and waiting for user input.
    // Begin work here.
}
Paul Williams
Thanks for the idea. But the idle event is a little bit too late, I think. What if the PC is in full load due to some other apps ?
BitKFu
This is Application.Idle, which is not related to processor load. Idle means your UI thread is waiting for input, which means it has finished initializing.
Paul Williams
Ok. I didn't know that fact. Thx
BitKFu