向Webbrowser控件中直接写入HTML内容的几种方法

2024-11-09 18:13:55
推荐回答(1个)
回答1:

用Webbrowser 中写入HTML 内容的几种方法 首先在Form_Load 中加入 WebBrowser1.Navigate about:blank 确保Webbrowser1 可用方法1: Dim s As String Dim stream As IStreams =s = s +s = s +s = s + hello worlds = s +s = s +WebBrowser1.Document.Write s方法2:Dim o Set o = WebBrowser1.Document.selection.createrange Debug.Print o If (Not o Is Nothing) Then o.pasteHTML 哈哈 Set o = NothingEnd IfC#:webBrowser1.Navigate( about:blank ); StreamReader sr = new StreamReader( test.htm ); string text = sr.ReadToEnd(); sr.Close(); webBrowser1.Document.Write(text);方法3: ''插入文本框Dim o Set o = WebBrowser1.Document.selection.createrange o.execCommand InsertTextArea , False, xxx 其中方法3 是采用了调用execCommand 并且传递控制命令的方法,通过这种方法还可以插入