public static void deleteRow(IHTMLElement m_oHTMLCtxMenu) { HTMLEditHelper htmledit = new HTMLEditHelper(); IHTMLTableRow row = htmledit.GetParentRow(m_oHTMLCtxMenu); int index = 0; if (row != null) { index = row.rowIndex; } IHTMLTable table = htmledit.GetParentTable(m_oHTMLCtxMenu); if (table == null) { return; } htmledit.DeleteRow(table, index); }
public static void insertColumn(IHTMLElement m_oHTMLCtxMenu) { HTMLEditHelper htmledit = new HTMLEditHelper(); IHTMLTableCell cell = m_oHTMLCtxMenu as IHTMLTableCell; int index = 0; if (cell != null) { index = cell.cellIndex; } IHTMLTable table = htmledit.GetParentTable(m_oHTMLCtxMenu); if (table == null) { return; } htmledit.InsertCol(table, index); }
public static void insertRow(IHTMLElement m_oHTMLCtxMenu) { HTMLEditHelper htmledit = new HTMLEditHelper(); IHTMLTableCell cell = m_oHTMLCtxMenu as IHTMLTableCell; IHTMLTableRow row = htmledit.GetParentRow(m_oHTMLCtxMenu); int index = 0; if (row != null) { index = row.rowIndex; } IHTMLTable table = htmledit.GetParentTable(m_oHTMLCtxMenu); if (table == null) { return; } htmledit.InsertRow(table, index, htmledit.Row_GetCellCount(row)); }
/// <summary> /// 表格弹出菜单事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void tableToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.Name) { case "delcolToolStripMenuItem": { GeneralMethodsForDesign.deleteColumn(currentEle); } break; case "inscolToolStripMenuItem": { GeneralMethodsForDesign.insertColumn(currentEle); } break; case "delrowToolStripMenuItem": { GeneralMethodsForDesign.deleteRow(currentEle); break; } case "insrowToolStripMenuItem": { GeneralMethodsForDesign.insertRow(currentEle); break; } case "splitToolStripMenuItem": { #region HTMLEditHelper hp = new HTMLEditHelper(); IHTMLTable tb = hp.GetParentTable(currentEle); IHTMLTableRow tr = hp.GetParentRow(currentEle); IHTMLTableCell td = currentEle as IHTMLTableCell; int rowindex = tr.rowIndex; int rowcount = hp.GetRowCount(tb); int colindex = td.cellIndex; hp.Row_InsertCell(tr, colindex - 1); int currentSpan = 0; for (int k = 0; k < colindex; k++) { currentSpan += (hp.Row_GetCell(tr, colindex) as IHTMLTableCell).colSpan; } for (int i = 0; i < rowcount; i++) { if (i != rowindex) { IHTMLTableRow tr0 = hp.GetRow(tb, i) as IHTMLTableRow; IHTMLTableCell td0 = hp.Row_GetCell(tr0, colindex) as IHTMLTableCell; int rowSpan = 0; int cellnum = 0; do { rowSpan += (hp.Row_GetCell(tr0, cellnum) as IHTMLTableCell).colSpan; td0 = hp.Row_GetCell(tr0, cellnum) as IHTMLTableCell; cellnum++; }while (rowSpan <= currentSpan); if (td0.colSpan > 0) { td0.colSpan += 1; } } else { continue; } } break; #endregion } case "mergerToolStripMenuItem": { #region HTMLEditHelper hp = new HTMLEditHelper(); /* IHTMLTableRow tr = hp.GetParentRow(currentEle); * int colNum = hp.Row_GetCellCount(tr); * MergeCellForm mergeCel = new MergeCellForm(colNum); * if (mergeCel.ShowDialog() == DialogResult.OK) * { * * }*/ IHTMLTableCell c1 = currentEle as IHTMLTableCell; mshtml.IHTMLDOMNode n1 = c1 as mshtml.IHTMLDOMNode; IHTMLTableCell c2 = hp.PreviousSibling(n1) as IHTMLTableCell; IHTMLTableCell c3 = hp.NextSibiling(n1) as IHTMLTableCell; IHTMLElement e1 = c1 as IHTMLElement; IHTMLElement e2 = c2 as IHTMLElement; IHTMLElement e3 = c3 as IHTMLElement; int span = c1.colSpan; string tdtext = e1.innerHTML; if (c2 != null) { span += c2.colSpan; tdtext = e2.innerText + tdtext; hp.RemoveNode(e2, false); } if (c3 != null) { span += c3.colSpan; tdtext += e3.innerText; hp.RemoveNode(e3, false); } c1.colSpan = span; e1.innerHTML = tdtext; break; #endregion } case "otherToolStripMenuItem": { break; } } }