共用方式為


CWinFormsControl 類別

提供裝載 Windows Form 控制項的基本功能。

語法

template<class TManagedControl>
class CWinFormsControl : public CWnd

參數

TManagedControl
要顯示在 MFC 應用程式中的 .NET Framework Windows Forms 控制項。

成員

公用建構函式

名稱 描述
CWinFormsControl::CWinFormsControl 建構 MFC Windows Forms 控制項包裝函式物件。

公用方法

名稱 描述
CWinFormsControl::CreateManagedControl 在 MFC 容器中建立 Windows Forms 控制項。
CWinFormsControl::GetControl 擷取 Windows Forms 控制項的指標。
CWinFormsControl::GetControlHandle 擷取 Windows Forms 控制項的控制碼。

公用運算子

名稱 描述
CWinFormsControl::operator -> 取代運算式中的 CWinFormsControl::GetControl
CWinFormsControl::operator TManagedControl^ 將類型轉換成 Windows Forms 控制項的指標。

備註

類別 CWinFormsControl 提供裝載 Windows Form 控制項的基本功能。

如需使用 Windows Forms 的詳細資訊,請參閱 在 MFC 中使用 Windows Form 使用者控制項。

您的 MFC 程式碼不應該快取視窗控制碼(通常儲存在 m_hWnd 中)。 某些 Windows Forms 控制項屬性需要使用 DestroyWindowCreateWindow 來終結並重新建立基礎 Win32 Window 。 MFC Windows Forms 實作會處理控制項的 DestroyCreate 事件,以更新 m_hWnd 成員。

注意

MFC Windows Forms 整合僅適用于動態連結 MFC 的專案(定義 AFXDLL 的專案)。

需求

標頭: afxwinforms.h

CWinFormsControl::CreateManagedControl

在 MFC 容器中建立 Windows Forms 控制項。

inline BOOL CreateManagedControl(
    System::Type^ pType,
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    int nID)
inline BOOL CreateManagedControl(
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    int nID);

inline BOOL CreateManagedControl(
    DWORD dwStyle,
    int nPlaceHolderID,
    CWnd* pParentWnd);

inline BOOL CreateManagedControl(
    typename TManagedControl^ pControl,
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    int nID);

參數

pType
要建立之控制項的資料類型。 必須是 Type 資料類型。

dwStyle
要套用至控制項的視窗樣式。 指定視窗樣式 的組合 。 目前僅支援下列樣式:WS_TABSTOP、WS_VISIBLE、WS_DISABLED和WS_GROUP。

矩形
RECT 結構 ,定義控制項左上角和右下角的座標(僅限第一個多載)。

nPlaceHolderID
放在資源編輯器中之靜態位置持有者控制項的控制碼。 新建立的 Windows Forms 控制項會取代靜態控制項,並假設其位置、迭置順序和樣式(僅限第二個多載)。

pParentWnd
父視窗的指標。

nID
要指派給新建立控制項的資源識別碼。

pControl
與 CWinFormsControl 物件相關聯 之 Windows Forms 控制項的實例(僅限第四個多載)。

傳回值

如果成功,則傳回非零值。 如果失敗,則傳回零。

備註

這個方法會在 MFC 容器中具現化 .NET Framework Windows Forms 控制項。

方法的第一個多載會接受 .NET Framework 資料類型 pType ,讓 MFC 可以具現化此類型的新物件。 pType 必須是 Type 資料類型。

方法的第二個多載會根據 TManagedControl 類別的 CWinFormsControl 樣板參數建立 Windows Forms 控制項。 控制項的大小和位置是以傳遞至 方法的結構為基礎 RECT 。 只有 dwStyle 才對樣式很重要。

方法的第三個多載會建立一個 Windows Forms 控制項,以取代靜態控制項,終結它並假設其位置、z 順序和樣式。 靜態控制項僅做為 Windows Forms 控制項的預留位置。 建立控制項時,這個多載會結合 dwStyle 中的樣式 與靜態控制項的資源樣式。

方法的第四個多載可讓您傳入 MFC 將包裝的已具現化 Windows Forms 控制項 pControl 。 它的類型必須與 類別的 CWinFormsControl 樣板參數相同 TManagedControl

如需使用 Windows Form 控制項的範例,請參閱 在 MFC 中使用 Windows Form 使用者控制項。

CWinFormsControl::CWinFormsControl

建構 MFC Windows Forms 控制項包裝函式物件。

CWinFormsControl();

備註

當您呼叫 CWinFormsControl::CreateManagedControl 時,會具現化 Windows Forms 控制項。

CWinFormsControl::GetControl

擷取 Windows Forms 控制項的指標。

inline TManagedControl^ GetControl() const;

傳回值

傳回 Windows Forms 控制項的指標。

範例

請參閱 CWinFormsControl::CreateManagedControl

CWinFormsControl::GetControlHandle

擷取 Windows Forms 控制項的控制碼。

inline HWND GetControlHandle() const;

傳回值

傳回 Windows Forms 控制項的控制碼。

備註

GetControlHandle 是可傳回儲存在 .NET Framework 控制項屬性中的視窗控制碼的協助程式方法。 在呼叫 CWnd::Attach 期間,視窗控制碼值會 複製到 CWnd::m_hWnd

CWinFormsControl::operator ->

取代運算式中的 CWinFormsControl::GetControl

inline TManagedControl^  operator->() const;

備註

此運算子提供方便的語法,以取代 GetControl 運算式中。

如需 Windows Forms 的詳細資訊,請參閱 在 MFC 中使用 Windows Form 使用者控制項。

CWinFormsControl::operator TManagedControl^

將類型轉換成 Windows Forms 控制項的指標。

inline operator TManagedControl^() const;

備註

這個運算子會傳遞 CWinFormsControl<TManagedControl> 至接受 Windows Forms 控制項指標的函式。

另請參閱

CWinFormsDialog 類別
CWinFormsView 類別