簡體   English   中英

來自其他類的主要形式的呼叫方法

[英]Call method of main form from other class

我想知道從子窗體方法調用修改mainForm的方法的最干凈方法是什么。

我想保持mainForm禁用,直到初始子窗體完成。 現在,我已經將mainForm對象簡單地傳遞給了子窗體,並且該子窗體執行mainForm.Enabled = true並在完成時自行關閉。 這樣傳遞整個mainForm是不是很不明智? 操作系統是怎么做到的?

Application.OpenForms[0]

您可以獲取主窗口的實例(作為主窗口類型廣播)。 如果將方法公開,則可以將方法或屬性公開,也可以從第二個窗口中對其進行調用。

編輯:

您需要參考

using System.Windows.Forms;

訪問Application對象。

您可以公開mainForm的Enabled屬性:

public bool FormEnabled{
    get{ return this.Enabled;}
    set{ this.Enabled = value;}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM