2017-09-26 31 views
1

我有一個函數,將從不同的形式調用。這個 函數在參數中有obj形式,我想查看這個表格obj 在我的應用程序中有哪些表格。函數獲取參數表格的類型

public void callAsPopup(System.Windows.Forms.Form frm) 
{ 
    if(frm.GetType()==frmBatch) 
    this.CenterToParent(); 
    this.Show(); 
} 

這裏frmBatch的形式之一,在我的應用程序

+0

現在我們知道你想要什麼。但你也有問題嗎? –

+0

用這段代碼我錯誤'frmBatch是一個類型位被用作變量' –

回答

1

我們的is keyword檢查類型

public void callAsPopup(System.Windows.Forms.Form frm) 
{ 
    // sanity check to avoid crash on the Show call. 
    if(frm == null) 
     return; 

    if(frm is frmBatch) 
     this.CenterToParent(); 
    this.Show(); 
}