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
。