public HeaderCell[] GetMergedCells(LabelInfo info) { int count = info.MergedColMax - info.MergedColMin + 1; HeaderCell[] MergedCells = new HeaderCell[count]; for (int i = 0; i < count; i++) { HeaderCell cell = GetCell(info.RowIndex, i + info.MergedColMin); MergedCells[i] = cell; } return(MergedCells); }
private void MyClick(object sender, System.EventArgs e) { Label lctl = sender as Label; LabelInfo lblinfo = (LabelInfo)lctl.Tag; if (_CurCell == null || this.SelCount == 0) { _SelCells.Clear(); _SelCells.Add(lctl); } else { int row = _CurCell.Row; int col = _CurCell.Col; if (row == lblinfo.RowIndex && this.SelCount == 1) { int mincol = Math.Min(col, lblinfo.MergedColMax); int maxcol = Math.Max(col, lblinfo.MergedColMax); for (int i = mincol; i <= maxcol; i++) { if (this.ColsToMerge.Contains(i)) { _SelCells.Clear(); _SelCells.Add(lctl); _CurCell = GetCell(lblinfo.RowIndex, lblinfo.MergedColMin); if (this.txtEdit != null) { this.txtEdit.Text = this._CurCell.Text; } this.DrawSelCells(); return; } } _SelCells.Clear(); this.AddLabelToArray(row, mincol, maxcol); } else { _SelCells.Clear(); _SelCells.Add(lctl); } } _CurCell = GetCell(lblinfo.RowIndex, lblinfo.MergedColMin); this.DrawSelCells(); if (this.txtEdit != null) { this.txtEdit.Text = this._CurCell.Text; } }
public HeaderCell MergeCells() { if (this.SelCount <= 1) { return(null); } int count = this.SelCount; for (int i = 0; i < this.SelCount; i++) { Label SelLbl = this._SelCells[i] as Label; LabelInfo lblinfo = (LabelInfo)SelLbl.Tag; if (lblinfo.MergedColMax - lblinfo.MergedColMin > 0) { count += lblinfo.MergedColMax - lblinfo.MergedColMin; } } int row = 0; int col = -1; for (int i = 0; i < this.SelCount; i++) { Label SelLbl = this._SelCells[i] as Label; LabelInfo lblinfo = (LabelInfo)SelLbl.Tag; row = lblinfo.RowIndex; if (col < 0) { col = lblinfo.MergedColMin; } else { col = Math.Min(col, lblinfo.MergedColMin); } for (int k = lblinfo.MergedColMin; k <= lblinfo.MergedColMax; k++) { HeaderCell hc = GetCell(lblinfo.RowIndex, k); hc.MergerdCount = count; hc.MergerdIndex = i + k - lblinfo.MergedColMin; } } if (col < 0 || col >= this.ColCount || row < 0 || row >= this.RowCount) { return(null); } return(GetCell(row, col)); }
public void UnMergeCells() { if (this.SelCount <= 0) { //MessageBox.Show("Please select the cells you want to unmerge!","Select cells",MessageBoxButtons.OK,MessageBoxIcon.Information); return; } for (int i = 0; i < this.SelCount; i++) { Label SelLbl = this._SelCells[i] as Label; LabelInfo lblinfo = (LabelInfo)SelLbl.Tag; HeaderCell[] selcells = this.GetMergedCells(lblinfo); foreach (HeaderCell hc in selcells) { if (hc == null) { return; } hc.MergerdCount = 0; hc.MergerdIndex = 0; } } }
public void DrawSelCells() { foreach (Control ctrl in this._HeaderContainer.Controls) { if (ctrl.Name.StartsWith("cell")) { continue; } ctrl.BackColor = Control.DefaultBackColor; LabelInfo lblInfo = (LabelInfo)ctrl.Tag; if (lblInfo.DefaultBackColor != Color.Empty) { ctrl.BackColor = lblInfo.DefaultBackColor; } } foreach (Object obj in this._SelCells) { Label lbllast = obj as Label; lbllast.BackColor = Color.Tomato; } }
public void PaintCells(Control Ctrl, Rectangle rect, IMultiHeader HeaderView) { ArrayList formats = new ArrayList(); HeaderView.GetPrnHeader(out formats); this._HeaderContainer = Ctrl; if (this.ColCount <= 0) { return; } int lblWidth = rect.Width / this.ColCount; int lblHeight = rect.Height / this.RowCount; this._SelCells.Clear(); this._CurCell = null; #region add Controls for (int i = 0; i < this.RowCount; i++) { int lblLocX = rect.X; int lblLocY = rect.Y + i * lblHeight; for (int j = 0; j < GetRow(i).ColCount; j++) { HeaderCell hc = GetCell(i, j); Rectangle LabelRect = new Rectangle(lblLocX, lblLocY, lblWidth, lblHeight); LabelInfo info = new LabelInfo(); info.RowIndex = i; string Lbltext = hc.Text; info.MergedColMax = info.MergedColMin = j; string LblName = string.Format("{0}", i * ColCount + j); if (hc.MergerdCount > 0) { LabelRect.Width = hc.MergerdCount * lblWidth; j += hc.MergerdCount - 1; info.MergedColMax = j; } #region Modify codes at 2008-11-5 15:16:51@Simon if (this.ColsToMerge.Contains(j) && (HeaderView.HaveHeader || i > 0)) { lblLocX += LabelRect.Width; continue; } #endregion //End Modify info.LblLoc = LabelRect.Location; info.LblSize = LabelRect.Size; Label lblcell = new Label(); lblcell.Name = LblName; lblcell.Text = Lbltext; lblcell.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; lblcell.BackColor = Control.DefaultBackColor; if (i == 0 && !HeaderView.HaveHeader && j < formats.Count) { StringFormatFlags strflags = (StringFormatFlags)formats[j]; //Added this code at 2008-11-5 8:53:15@Simon if ((strflags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical) { lblcell.Paint += new PaintEventHandler(DrawLabelVertical); } } info.DefaultBackColor = lblcell.BackColor; lblcell.Tag = info; if (this.GridLine) { lblcell.BorderStyle = BorderStyle.FixedSingle; lblcell.Location = LabelRect.Location; if (this.ColsToMerge.Contains(j)) { lblcell.Size = new Size(lblWidth, rect.Height); Ctrl.Controls.Add(lblcell); lblLocX += LabelRect.Width; continue; } else { lblcell.Size = LabelRect.Size; } } else { lblcell.BorderStyle = BorderStyle.None; lblcell.Location = new Point(LabelRect.X + 1, LabelRect.Y + 1); if (this.ColsToMerge.Contains(j)) { lblcell.Size = new Size(LabelRect.Width - 2, rect.Height - 2); lblLocX += LabelRect.Width; Ctrl.Controls.Add(lblcell); continue; } else { lblcell.Size = new Size(LabelRect.Width - 2, LabelRect.Height - 2); } } lblLocX += LabelRect.Width; lblcell.Click += new System.EventHandler(MyClick); Ctrl.Controls.Add(lblcell); } } #endregion }