0

formプログラムにどれが開かれているかを知らせ、そのために特定のアクションを実行したいと考えていformます。フォームは概要を含むメイン ウィンドウで開かれ、ユーザーは画像をクリックして新しいフォームを開くことができます。このメイン ウィンドウは、開きたいフォームの BaseForm ではありません。

何が開いているかを確認するためformに、次のコードを試しました。

bool thisOne;
bool theOtherOne;

private void FormCheck()
{
    foreach (Form form in Application.OpenForms)
    {
        if (form is frmRectangle)
        {
            thisOne = true;
            theOtherOne = false;
            break;
        }

        if (form is frmCircular)
        {
            theOtherOne = true;
            thisOne = false;
            break;
        }
    }
}

フォーム関連booleansを true に設定したので、次のような別の関数でそれらを使用できます。

private void ActionTime()
{
    if (thisOne)
        Debug.WriteLine("ThisOne is open");
        //Do some stuff for the ThisOne form
    if (theOtherOne)
        Debug.WriteLine("TheOtherOne is open");
        //Do some stuff for TheOtherOne form
}

ActionTime は によって呼び出されますClickEventが、アクションは発生しません... で何か問題が発生していると思いますforeach-loop

4

0 に答える 0