|
■No57898 (rinrin さん) に返信
> WebBrowserにTextBoxに入力した文字列(<font color="red">Test</font>)を
> IEなどに表示するような形式で表示したいのですが、どうしたらいいのでしょうか。
「<font color="red">Test</font>」と表示したいのか、
赤文字「Test」と表示したいのか読み取れなかったのですが、
とりあえず、こんな感じで。
Public Class Form1
Private sc As SplitContainer
Private WithEvents wb1 As WebBrowser
Private wb2 As WebBrowser
Public Sub New()
InitializeComponent()
sc = New SplitContainer()
sc.Dock = DockStyle.Fill
sc.Orientation = Orientation.Horizontal
Controls.Add(sc)
wb1 = New WebBrowser()
wb2 = New WebBrowser()
wb1.Dock = DockStyle.Fill
wb2.Dock = DockStyle.Fill
sc.Panel1.Controls.Add(wb1)
sc.Panel2.Controls.Add(wb2)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'空ページを表示し、Documentの準備ができるまで待つ
AddHandler wb1.DocumentCompleted, AddressOf SetWb1
AddHandler wb2.DocumentCompleted, AddressOf SetWb2
wb1.Navigate("about:blank")
wb2.Navigate("about:blank")
End Sub
Private Sub SetWb1(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
RemoveHandler wb1.DocumentCompleted, AddressOf SetWb1
'wb1.Document.Write("<font color=""red"">Test</font>")
'wb1.DocumentText = "<font color=""red"">Test</font>"
'テキストとして送り込む
wb1.Document.Body.InnerText = "<font color=""red"">Test</font>"
End Sub
Private Sub SetWb2(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
RemoveHandler wb2.DocumentCompleted, AddressOf SetWb2
'Dim elm As HtmlElement = wb2.Document.CreateElement("font")
'elm.SetAttribute("color", "red")
'elm.InnerText = "Test"
'wb2.Document.Body.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterBegin, elm)
'HTML として送り込む
wb2.Document.Body.InnerHtml = "<font color=""red"">Test</font>"
End Sub
End Class
|