1.修改窗体: \UI\DocInfo\Document.cs
private void menuTableAdd_Click(object sender, EventArgs e)
{
HtmlEditor.TableAddRow(htmlDesign);
}
private void menuTableDel_Click(object sender, EventArgs e)
{
HtmlEditor.TableDeleteRow(htmlDesign);
}
2.修改类:HtmlEditor.cs
public static void TableAddRow(WebBrowser pWb) {
int rowIndex = 0;
HTMLTable table = GetSelectTable(pWb, ref
rowIndex);
if (table != null) {
int colLen =
table.cells.length / table.rows.length;
HTMLTableRow row =
(HTMLTableRow)table.insertRow(rowIndex);
for (int i = 0; i
< colLen; i++) {
object elCell =
row.insertCell(i);
HTMLTableCell cell =
(HTMLTableCell)elCell;
cell.innerText =
"";
}
}
}
public static void TableDeleteRow(WebBrowser pWb)
{
int rowIndex = 0;
HTMLTable table =
GetSelectTable(pWb, ref rowIndex);
if (table != null)
{
table.deleteRow(rowIndex);
}
}
public static HTMLTable GetSelectTable(WebBrowser pWb,ref int
pRowIndex) {
mshtml.IHTMLDocument2 doc2 =
(mshtml.IHTMLDocument2)pWb.Document.DomDocument;
mshtml.IHTMLTxtRange rangeObj =
(mshtml.IHTMLTxtRange)(doc2.selection.createRange());
mshtml.IHTMLElement ele =
rangeObj.parentElement();
int rowIndex = 0;
if
(ele != null) {
for (int i = 0; i < 100; i++)
{
if (ele == null) break;
if
(ele.tagName.ToLower() == "table") {
break;
}
if (ele.tagName.ToLower()
== "tr") {
HTMLTableRow tr =
(HTMLTableRow)ele;
rowIndex =
tr.rowIndex;
}
ele =
ele.parentElement;
}
}
if (ele
!= null && ele.tagName.ToLower() == "table") {
pRowIndex = rowIndex;
return (HTMLTable)ele;
}
else {
return null;
}
}