/// <summary> /// 将Table对象复制一份 /// </summary> private void CopyObject(AojTable tbObjectFrom, AojTable tbObjectTo) { #region 表格 tbObjectTo.Name = tbObjectFrom.Name; tbObjectTo.Left = tbObjectFrom.Left; tbObjectTo.Top = tbObjectFrom.Top; tbObjectTo.Width = tbObjectFrom.Width; tbObjectTo.Height = tbObjectFrom.Height; tbObjectTo.MyDocument = new CellDocument(true); #endregion #region 表格列 Column colItem; Column colNewItem; foreach (string strColId in tbObjectFrom.MyDocument.ColumnCollection.Keys) { colItem = tbObjectFrom.MyDocument.ColumnCollection[strColId]; colNewItem = new Column(); colNewItem.ColumnID = colItem.ColumnID; colNewItem.ColumnRatio = colItem.ColumnRatio; colNewItem.ColumnWidth = colItem.ColumnWidth; tbObjectTo.MyDocument.ColumnCollection.Add(strColId, colNewItem); } #endregion #region 表格行 Row rowItem; Row rowNewItem; Cell cellNewItem; foreach (string strRowId in tbObjectFrom.MyDocument.RowCollection.Keys) { rowItem = tbObjectFrom.MyDocument.RowCollection[strRowId]; rowNewItem = new Row(); rowNewItem.RowID = rowItem.RowID; rowNewItem.RowHeight = rowItem.RowHeight; rowNewItem.RowRatio = rowItem.RowRatio; tbObjectTo.MyDocument.RowCollection.Add(strRowId, rowNewItem); #region 单元格 int index = 0; foreach (string strColId in tbObjectFrom.MyDocument.ColumnCollection.Keys) { colItem = tbObjectFrom.MyDocument.ColumnCollection[strColId]; cellNewItem = new Cell(); cellNewItem.ColumnID = colItem.ColumnID; cellNewItem.RowID = rowItem[index].RowID; cellNewItem.Text = rowItem[index].Text; cellNewItem.TextFamilyName = rowItem[index].TextFamilyName; cellNewItem.TextFontSize = rowItem[index].TextFontSize; cellNewItem.TextFontStyle = rowItem[index].TextFontStyle; cellNewItem.TextColor = rowItem[index].TextColor; cellNewItem.ObjectAlignment = rowItem[index].ObjectAlignment; cellNewItem.ObjectLineAlignment = rowItem[index].ObjectLineAlignment; rowNewItem.Add(cellNewItem); ++index; } #endregion } #endregion }
/// <summary> /// 对表格中的列进行选择 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lisBoxColumn_SelectedIndexChanged(object sender, EventArgs e) { Column columnInfo = (Column)this.lisBoxColumn.SelectedValue; this.columnCurrent = columnInfo; if (columnInfo != null) { #region 列 this.txtColumnName.Text = columnInfo.ColumnID; this.txtColumnWidth.Text = columnInfo.ColumnWidth.ToString(); #endregion } else { #region 列 this.txtColumnName.Text = string.Empty; this.txtColumnWidth.Text = string.Empty; #endregion } }
/// <summary> /// 添加表格列 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddColumn_Click(object sender, EventArgs e) { string columnId = "w"+this.GetColumnCountInfo().ToString(); Column colNew = new Column(); colNew.ColumnID = columnId; colNew.ColumnWidth = 30; this.tbTempObject.MyDocument.ColumnCollection.Add(columnId, colNew); this.tbTempObject.Width += colNew.ColumnWidth; this.txtTableWidth.Text = this.tbTempObject.Width.ToString(); this.SetColumnRatioInfo(); this.DoBusinessAboutAddColumn(columnId); #region 表格列 this.lisBoxColumn.DataSource = this.GetColumnData(this.tbTempObject); #endregion #region 表格行 this.listBoxRow.SelectedIndex = -1; #endregion }
/// <summary> /// 初始化网格数据结构对象操作 /// </summary> private void InitializeTableCellDocument() { #region 绘制表结构时候的初始化操作 Row rowItem = new Row(); rowItem.RowID = "h1"; rowItem.RowRatio = 0.5f; this.AddRow("h1", rowItem); rowItem = new Row(); rowItem.RowID = "h2"; rowItem.RowRatio = 0.5f; this.AddRow("h2", rowItem); Column colItem = new Column(); colItem.ColumnID = "w1"; colItem.ColumnRatio = 0.5f; this.AddColumn("w1", colItem); colItem = new Column(); colItem.ColumnID = "w2"; colItem.ColumnRatio = 0.5f; this.AddColumn("w2", colItem); #endregion }
/// <summary> /// 添加表格列的时候,给每行添加相关的单元格 /// </summary> /// <param name="column">新增的表格列对象</param> private void DoBusinessAboutAddColumn(Column column) { Cell cellItem; foreach (Row rowItem in this.dicRowCollection.Values) { cellItem = new Cell(); cellItem.RowID = rowItem.RowID; cellItem.ColumnID = column.ColumnID; rowItem.Add(cellItem); } }
/// <summary> /// 添加表格列 /// </summary> /// <param name="strColumnID">表格列横项目名称</param> /// <param name="column">新增的表格列对象</param> public void AddColumn(string strColumnID, Column column) { if (!this.dicColumnCollection.ContainsKey(strColumnID)) { this.dicColumnCollection.Add(strColumnID, column); //给每行添加相关的单元格 this.DoBusinessAboutAddColumn(column); } }
/// <summary> /// 从xml文档中获得对象 /// </summary> public override void OpenFormXML(XmlNode objNode) { if (objNode != null) { #region 对象的相关属性 this.Name = objNode.Attributes["Id"].Value; this.Left = float.Parse(objNode.Attributes["PositionX"].Value); this.Top = float.Parse(objNode.Attributes["PositionY"].Value); this.Width = float.Parse(objNode.Attributes["Width"].Value); this.Height = float.Parse(objNode.Attributes["Height"].Value); #endregion XmlNodeList lstColumn = objNode.SelectNodes("Column"); XmlNodeList lstRow = objNode.SelectNodes("Row"); if (lstColumn != null && lstRow != null) { int columnCount = lstColumn.Count; int rowCount = lstRow.Count; if (columnCount > 0 && rowCount > 0) { Column colItem; Row rowItem; XmlNodeList lstChildNode; Cell cellItem; XmlNode childCellNode; this.myDocument = new CellDocument(true); #region 表格列 foreach (XmlNode nodeColumnItem in lstColumn) { colItem = new Column(); colItem.ColumnID = nodeColumnItem.Attributes["Id"].Value; colItem.ColumnWidth = float.Parse(nodeColumnItem.Attributes["Width"].Value); this.myDocument.AddColumn(colItem.ColumnID, colItem); #region 表格行 foreach (XmlNode nodeRowItem in lstRow) { lstChildNode = nodeRowItem.SelectNodes("Cell"); if (lstChildNode != null && lstChildNode.Count > 0) { if (columnCount == lstChildNode.Count) { rowItem = new Row(); rowItem.RowID = nodeRowItem.Attributes["Id"].Value; rowItem.RowHeight = float.Parse(nodeRowItem.Attributes["Height"].Value); this.myDocument.AddRow(rowItem.RowID, rowItem); rowItem.Clear(); #region 单元格 foreach (XmlNode nodeCellItem in lstChildNode) { cellItem = new Cell(); cellItem.ColumnID = colItem.ColumnID; cellItem.RowID = rowItem.RowID; cellItem.Width = colItem.ColumnWidth; cellItem.Height = rowItem.RowHeight; childCellNode = nodeCellItem.SelectSingleNode("Text"); if (childCellNode != null) { cellItem.TextFamilyName = childCellNode.Attributes["FamilyName"].Value; cellItem.TextFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), childCellNode.Attributes["FontStyle"].Value); cellItem.TextFontSize = float.Parse(childCellNode.Attributes["FontSize"].Value); cellItem.TextColor = ColorTranslator.FromHtml(childCellNode.Attributes["Color"].Value); cellItem.Text = childCellNode.InnerText; this.SetStringAlignmentFormat(cellItem, childCellNode.Attributes["Alignment"].Value); } rowItem.Add(cellItem); } #endregion } } } #endregion } #endregion } } //设置表格中每列的比例 this.SetColumnRatioInfo(); //设置表格中每行的比例 this.SetRowRatioInfo(); } }