日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

演练:在 Windows 窗体中承载 Windows Presentation Foundation 复合控件 【转载】

發(fā)布時間:2024/4/14 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 演练:在 Windows 窗体中承载 Windows Presentation Foundation 复合控件 【转载】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

http://msdn.microsoft.com/zh-cn/library/ms745781.aspx

更新:2007 年 11 月

本演練演示如何創(chuàng)建 WPF 復(fù)合控件,并通過使用 ElementHost 控件在 Windows 窗體控件和窗體中承載它。

在本演練中,將實(shí)現(xiàn)一個包含兩個子控件的 WPFUserControl。 UserControl 顯示一個三維 (3-D) 圓錐。使用 WPF 呈現(xiàn)三維對象比使用 Windows 窗體更簡單。因此,對于在 Windows 窗體中創(chuàng)建三維圖形,承載 WPFUserControl 類非常有意義。

本演練涉及以下任務(wù):

  • 創(chuàng)建 WPFUserControl。

  • 創(chuàng)建 Windows 窗體宿主項(xiàng)目。

  • 承載 WPFUserControl。

有關(guān)本演練中所闡釋任務(wù)的完整代碼清單,請參見在 Windows 窗體中承載 Windows Presentation Foundation 復(fù)合控件的示例。

注意 顯示的對話框和菜單命令可能與“幫助”中所述的有所不同,具體取決于當(dāng)前的設(shè)置或版本。若要更改設(shè)置,請?jiān)凇肮ぞ摺辈藛紊线x擇“導(dǎo)入和導(dǎo)出設(shè)置”。有關(guān)更多信息,請參見 Visual Studio 設(shè)置。

先決條件

您需要以下組件來完成本演練:

  • Visual Studio 2008.

創(chuàng)建 UserControl

創(chuàng)建 UserControl
  • 創(chuàng)建一個名為 HostingWpfUserControlInWf 的 WPF 用戶控件庫項(xiàng)目。

  • 在 WPF 設(shè)計(jì)器中打開 UserControl1.xaml。

  • 用下面的代碼替換生成的代碼。

    該代碼定義一個包含兩個子控件的 System.Windows.Controls.UserControl。第一個子控件是 System.Windows.Controls.Label 控件;第二個控件是顯示三維圓錐的 Viewport3D 控件。

  • 創(chuàng)建 Windows 窗體宿主項(xiàng)目

    創(chuàng)建宿主項(xiàng)目
  • 將名為 WpfUserControlHost 的 Windows 應(yīng)用程序項(xiàng)目添加到解決方案中。有關(guān)更多信息,請參見“添加新項(xiàng)目”對話框。

  • 在解決方案資源管理器中,添加一個對名為 WindowsFormsIntegration.dll 的 WindowsFormsIntegration 程序集的引用。

  • 添加對以下 WPF 程序集的引用:

    • PresentationCore

    • PresentationFramework

    • WindowsBase

  • 添加對 HostingWpfUserControlInWf 項(xiàng)目的引用。

  • 在解決方案資源管理器中,將 WpfUserControlHost 項(xiàng)目設(shè)置為啟動項(xiàng)目。

  • 承載 Windows Presentation Foundation UserControl

    承載 UserControl
  • 在 Windows 窗體設(shè)計(jì)器中打開 Form1。

  • 在“屬性”窗口中,單擊“事件”,然后雙擊 Load 事件以創(chuàng)建事件處理程序。

    代碼編輯器打開并定位到新生成的 Form1_Load 事件處理程序。

  • 將 Form1.cs 中的代碼替換為以下代碼。

    Form1_Load 事件處理程序?qū)?chuàng)建一個 UserControl1 實(shí)例,并將其添加到ElementHost 控件的子控件集合中。ElementHost 控件將被添加到窗體的子控件集合中。

    Visual Basic

    Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.Windows.FormsImports System.Windows.Forms.IntegrationPublic Class Form1Inherits FormPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' Create the ElementHost control for hosting the' WPF UserControl.

    Dim host As New ElementHost()

    host.Dock = DockStyle.Fill' Create the WPF UserControl.Dim uc As New HostingWpfUserControlInWf.UserControl1()' Assign the WPF UserControl to the ElementHost control's' Child property.host.Child = uc' Add the ElementHost control to the form's' collection of child controls.Me.Controls.Add(host)End SubEnd Class
  • 按 F5 生成并運(yùn)行該應(yīng)用程序。

  • 轉(zhuǎn)載于:https://www.cnblogs.com/chenxizhang/archive/2009/05/07/1451281.html

    總結(jié)

    以上是生活随笔為你收集整理的演练:在 Windows 窗体中承载 Windows Presentation Foundation 复合控件 【转载】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。