Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control.IsAccessible

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

like image 485
BitKFu Avatar asked May 11 '10 19:05

BitKFu


2 Answers

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.

like image 112
Scott Chamberlain Avatar answered Sep 28 '22 02:09

Scott Chamberlain


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.
}
like image 20
Paul Williams Avatar answered Sep 28 '22 02:09

Paul Williams