Hi Peter,
I really appreciate your help on this.
I think it is what I wanted. I'm almost positive that we
can implement all the features that we need with these,
but I'm having difficulties to figure them out.
I was able to open up an HTML file using WebBrowser
control, and manipulate it using MSHTML.
But, I still have some issues to solve.
First of all, how do I save the document after modifying
it without asking for the users - which means, we don't
want to show "Save as" popup to users. We want to save it
programmatically.
And, what I want to implement is that when I select some
text in the browser control, and click a button, it
inserts a HTML tag, such as <a name.> tag or <font> tag,
around the text.
For example,
Text in HTML : 1234567
if you have selected "345"
the original source would be : 12<a name="tag_1">345</a>67
I could make it somehow, but it doesn't always work, for
example,
Original source : 12<a name="tag_1">345</a>67
If you have selected "56"
The source HTML would be : 12<a
name="tag_1">34</a><a name="tag_2"> <a
name="tag_1">5</a>6</a>7
So, it's screwed up the previous HTML tags sometimes.
Please take a look at my code sample below, and advise me
if you have better solution for my case.
Thanks very much again for your help.
################################################
# Sample VB Code
################################################
Public Class frmTest
Inherits System.Windows.Forms.Form
Private doc As mshtml.HTMLDocument
Private idx As Long
Private Sub frmTest_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
AxWebBrowser1.Navigate2("C:\test.html")
doc = AxWebBrowser1.Document
idx = 0
End Sub
Private Sub Button1_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim rg As mshtml.IHTMLTxtRange
Dim sID As String
idx = idx + 1
sID = "myID_" & idx
If doc.selection.type = "Text" Then
'(1.1)
doc.execCommand("CreateBookmark", False, sID)
rg = doc.selection.createRange
If Not rg Is Nothing Then
'(2.1)
rg.pasteHTML("<a name=""" & sID
& """></a><span class=""my_class"">" & rg.htmlText
& "</span>")
'(2.2)
rg.pasteHTML("<a name=""" & sID
& """></a><span class=""my_class"">" & rg.text
& "</span>")
'(3.1)
rg.pasteHTML("<a name=""" & sID
& """><span class=""my_class"">" & rg.htmlText
& "</span></a>")
'(3.2)
rg.pasteHTML("<a name=""" & sID
& """><span class=""my_class"">" & rg.text
& "</span></a>")
'(4.1)
rg.pasteHTML("<span id=""" & sID & """
class=""my_class"">" & rg.htmlText & "</span>")
'(4.2)
rg.pasteHTML("<span id=""" & sID & """
class=""my_class"">" & rg.text & "</span>")
Else
MsgBox("Invalid selection")
End If
End If
End Sub
End Class
################################################
# Sample HTML - test.html
################################################
<html>
<head>
<title>Test</title>
<style type="text/css">
.my_class {
color: rgb(255,0,0);
}
</style>
</head>
<body>
<h1>Test HTML page
<p>12<font color="#ff0000">34</font>567890
ABCDEF<font
color="#ffff00">GHIJKL</font>MNOPQRSTUVWXYZ</p>
<p>123<a name="myID_100">456</a>7890 ABCD<span
class="my_class">EFG</span>HIJKLMNOPQRSTUVWXYZ</p>
</body>
</html>
-----Original Message-----
Hi Jay,
I look forward to hearing from you.
If you have any concern on this problem, please feel
free to post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and
confers no rights.
.