簡體   English   中英

無法將類型'System.Windows.Forms.Control'隱式轉換為'object'

[英]Cannot implicitly convert type 'System.Windows.Forms.Control' to 'object'

我正在遍歷WPF演練:在WPF中托管Windows窗體復合控件。

基本上,它首先使用Windows Form創建了一個用戶控件,然后將其添加到WPF應用程序中。

我已經完成了用戶控制,現在我正在實現文件背后的代碼。 由於它只是從MSDN鏈接復制和粘貼代碼,因此讓我們看一下該方法。

private void Init(object sender, EventArgs e)
    {
        app = System.Windows.Application.Current;
        myWindow = (Window)app.MainWindow;
        myWindow.SizeToContent = SizeToContent.WidthAndHeight;
        wfh.TabIndex = 10;
        initFontSize = wfh.FontSize;
        initFontWeight = wfh.FontWeight;
        initFontFamily = wfh.FontFamily;
        initFontStyle = wfh.FontStyle;
        initBackBrush = (SolidColorBrush)wfh.Background;
        initForeBrush = (SolidColorBrush)wfh.Foreground;
        (wfh.Child as MyControl1).OnButtonClick += new MyControl1.MyControlEventHandler(Pane1_OnButtonClick);
        UIIsReady = true;
    }

發生錯誤

無法將類型'System.Windows.Forms.Control'隱式轉換為'object'

在代碼處:

(wfh.Child as MyControl1).OnButtonClick += new MyControl1.MyControlEventHandler(Pane1_OnButtonClick);

如何糾正?

最后自己弄清楚,我必須添加一個dll

System.Windows.Forms

WPF項目,但MSDN沒有提及。

暫無
暫無

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

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