欢迎转载!注明为 CSDN我一直在寻找原创
我看到网上有许多朋友在silverlight嵌入html都没有实现,我2年前就搞定了,以为SL4.0会出来就没有放出来,但发现SL5.0bata版也要在安装成脱离浏览器才能用,我实在看不下去了,只好把我的压箱底的东西拿出来了
因为CSDN不能传附件,但是可以传图片,我把源代码用rar压缩后把后缀名改为.gif了,需要的下载下来后把后缀改为.rar然后解压就行了,我用的是VS2010的SL4做的,因为我比较老土了用了13年VB了,程序就用VB.net 做的,学C#的朋友就撮合看把。 用网际快车或者迅雷下载后面的网址吧(http://hi.csdn.net/attachment/201105/27/0_1306507975155E.gif )
也可以看一下代码:
Imports System.Windows.Browser
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Public Div As System.Windows.Browser.HtmlElement
Public Iframe As System.Windows.Browser.HtmlElement
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Div = HtmlPage.Document.CreateElement("div")
Dim Form1 As System.Windows.Browser.HtmlElement
Form1 = HtmlPage.Document.GetElementById("form1")
If Form1 Is Nothing Then
MessageBox.Show("依托网页没有元素""form1""不能进行!!")
Return
End If
Form1.AppendChild(Div)
Div.SetStyleAttribute("ID", "EmbeddedBrowser1")
Div.SetStyleAttribute("position", "absolute")
Div.SetStyleAttribute("top", "100px")
Div.SetStyleAttribute("left", "100px")
Div.SetStyleAttribute("width", "1000px")
Div.SetStyleAttribute("height", "1000px")
Iframe = HtmlPage.Document.CreateElement("iframe")
Div.AppendChild(Iframe)
Iframe.SetAttribute("ID", "EmbeddedBrowserIframe1")
Iframe.SetStyleAttribute("top", "0px")
Iframe.SetStyleAttribute("left", "0px")
Iframe.SetStyleAttribute("width", "1000px")
Iframe.SetStyleAttribute("height", "1000px")
Iframe.SetAttribute("src", "http://www.sina.com")
End Sub
End Class
欢迎转载!注明为 CSDN我一直在寻找原创