/// <summary> /// 获取CheckStyle=Image时使用的Image /// </summary> public Image CheckBoxImage(I3CheckBoxColumn checkBoxColumn) { if (checkBoxColumn.CustomCheckImage != null) { return(checkBoxColumn.CustomCheckImage); } else { return(global::IE310.Table.Resources.I3Resource.CheckBoxColumnImage); } }
/// <summary> /// 计算点击哪个区域时进行编辑 /// </summary> /// <param name="checkBoxColumn"></param> /// <returns></returns> protected Rectangle CalcCheckBoxCheckRect(I3Row row, I3CheckBoxColumn checkBoxColumn) { if (checkBoxColumn.CheckBoxCheckStyle == I3CheckBoxCheckStyle.CheckInClientArea) { return(this.ClientRectangle); } else { return(this.CalcCheckBoxDisplayRect(row.Alignment, checkBoxColumn.CellAlignment, checkBoxColumn)); } }
/// <summary> /// Raises the PaintCell event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> public override void OnPaintCell(I3PaintCellEventArgs e) { if (e.Table.ColumnModel.Columns[e.Column] is I3CheckBoxColumn) { I3CheckBoxColumn column = (I3CheckBoxColumn)e.Table.ColumnModel.Columns[e.Column]; this.checkSize = column.CheckSize; this.drawText = column.DrawText; } else { this.checkSize = new Size(13, 13); this.drawText = true; } base.OnPaintCell(e); }
/// <summary> /// Gets the Rectangle that specifies the Size and Location of /// the check box contained in the current Cell /// </summary> /// <returns>A Rectangle that specifies the Size and Location of /// the check box contained in the current Cell</returns> protected Rectangle CalcCheckBoxDisplayRect(I3RowAlignment rowAlignment, I3ColumnAlignment columnAlignment, I3CheckBoxColumn checkBoxColumn) { if (checkBoxColumn.CustomCheckImage != null && checkBoxColumn.CustomCheckImageFillClient) { return(this.ClientRectangle); } Rectangle checkRect = new Rectangle(this.ClientRectangle.Location, this.CheckSize); if (checkRect.Height > this.ClientRectangle.Height) { checkRect.Height = this.ClientRectangle.Height; checkRect.Width = checkRect.Height; } switch (rowAlignment) { case I3RowAlignment.Center: { checkRect.Y += (this.ClientRectangle.Height - checkRect.Height) / 2; break; } case I3RowAlignment.Bottom: { checkRect.Y = this.ClientRectangle.Bottom - checkRect.Height; break; } } if (!this.DrawText) { if (columnAlignment == I3ColumnAlignment.Center) { checkRect.X += (this.ClientRectangle.Width - checkRect.Width) / 2; } else if (columnAlignment == I3ColumnAlignment.Right) { checkRect.X = this.ClientRectangle.Right - checkRect.Width; } } if (checkBoxColumn != null && checkBoxColumn.CheckBoxColumnStyle == I3CheckBoxColumnStyle.Image) { Size size = checkBoxColumn.CustomCheckImageSize; checkRect.X -= Convert.ToInt32((size.Width - checkRect.Width) / 2); checkRect.Width = size.Width; checkRect.Y -= Convert.ToInt32((size.Height - checkRect.Height) / 2); checkRect.Height = size.Height; } return(checkRect); }
/// <summary> /// Raises the Paint event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> protected override void OnPaint(I3PaintCellEventArgs e) { base.OnPaint(e); // don't bother if the Cell is null if (e.Cell == null) { return; } Rectangle checkRect = this.CalcCheckBoxDisplayRect(this.LineAlignment, this.Alignment, e.Table.ColumnModel.Columns[e.Column] as I3CheckBoxColumn); I3CheckBoxStates state = this.GetCheckBoxRendererData(e.Cell).CheckState; if (!e.Enabled) { if (e.Cell.CheckState == CheckState.Checked) { state = I3CheckBoxStates.CheckedDisabled; } else if (e.Cell.CheckState == CheckState.Indeterminate) { state = I3CheckBoxStates.MixedDisabled; } else // if (e.Cell.CheckState == CheckState.Unchecked) { state = I3CheckBoxStates.UncheckedDisabled; } } if (e.Table.ColumnModel.Columns[e.Column] is I3CheckBoxColumn) { I3CheckBoxColumn checkBoxColumn = e.Table.ColumnModel.Columns[e.Column] as I3CheckBoxColumn; switch (checkBoxColumn.CheckBoxColumnStyle) { case I3CheckBoxColumnStyle.RadioButton: // remove any mixed states switch (state) { case I3CheckBoxStates.MixedNormal: state = I3CheckBoxStates.CheckedNormal; break; case I3CheckBoxStates.MixedHot: state = I3CheckBoxStates.CheckedHot; break; case I3CheckBoxStates.MixedPressed: state = I3CheckBoxStates.CheckedPressed; break; case I3CheckBoxStates.MixedDisabled: state = I3CheckBoxStates.CheckedDisabled; break; } I3ThemeManager.DrawRadioButton(e.Graphics, checkRect, (I3RadioButtonStates)state); break; case I3CheckBoxColumnStyle.Image: if (e.Cell.Checked) { Image image = this.CheckBoxImage(checkBoxColumn); this.DrawImage(e.Graphics, image, checkRect, e.Cell.Enabled); } break; default: I3ThemeManager.DrawCheck(e.Graphics, checkRect, state); break; } } string text = ""; if (this.DrawText) { //string text = e.Cell.Text; text = e.Table.ColumnModel.Columns[e.Column].DataToString(e.Cell.Data); if (text != null && text.Length != 0) { Rectangle textRect = this.ClientRectangle; textRect.X += checkRect.Width + 1; textRect.Width -= checkRect.Width + 1; if (e.Enabled) { e.Graphics.DrawString(text, this.Font, this.ForeBrush, textRect, this.StringFormat); } else { e.Graphics.DrawString(text, this.Font, this.GrayTextBrush, textRect, this.StringFormat); } } } //cal needWidth needHeigth int maxWidth = e.Table.ColumnModel.Columns[e.Column].CellTextAutoWarp ? e.Table.ColumnModel.Columns[e.Column].Width : 0; int buttonWidth = checkRect.Width; CalCellNeedSize(e.Graphics, e.Cell, text, this.Font, this.StringFormat, maxWidth, 6 + buttonWidth, 0); if (e.Focused && e.Enabled) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }