/// <summary> /// Raises the Paint event /// </summary> /// <param name="e">A PaintHeaderEventArgs that contains the event data</param> protected override void OnPaint(I3PaintColumnHeaderEventArgs e) { base.OnPaint(e); if (e.Column == null) { return; } Rectangle textRect = this.ClientRectangle; Rectangle imageRect = Rectangle.Empty; if (e.Column.HeaderImage != null) { imageRect = this.CalcImageRect(); textRect.Width -= imageRect.Width; textRect.X += imageRect.Width; if (e.Column.HeaderImageOnRight) { imageRect.X = this.ClientRectangle.Right - imageRect.Width; textRect.X = this.ClientRectangle.X; } this.DrawColumnHeaderImage(e.Graphics, e.Column.HeaderImage, imageRect, e.Column.Enabled); } Rectangle arrowRect = Rectangle.Empty; if (e.Column.SortOrder != SortOrder.None) { arrowRect = this.CalcSortArrowRect(); arrowRect.X = textRect.Right - arrowRect.Width; textRect.Width -= arrowRect.Width; this.DrawSortArrow(e.Graphics, arrowRect, e.Column.SortOrder, e.Column.Enabled); } StringAlignment old = this.StringFormat.Alignment; string drawText = e.Column.Caption; if (e.Column.Caption.Length > 0 && textRect.Width > 0) { //计算绘制文本的起始点 switch (e.Column.HeaderAlignment) { case I3ColumnAlignment.Center: this.StringFormat.Alignment = StringAlignment.Center; break; case I3ColumnAlignment.Right: this.StringFormat.Alignment = StringAlignment.Far; break; default: this.StringFormat.Alignment = StringAlignment.Near; break; } //this.StringFormat.Trimming=EllipsisCharacter,指定文本超出范围时的剪切方式为以....替代 drawText = e.Column.Caption; int columnIndex = e.Table.ColumnModel.Columns.IndexOf(e.Column); switch (e.Table.ColumnHeaderDisplayMode) { case I3ColumnHeaderDisplayMode.Num: drawText = (columnIndex + 1).ToString(); break; case I3ColumnHeaderDisplayMode.Reference: drawText = I3ReferenceUtil.GetColumnName(columnIndex + 1); break; default: break; } if (e.Column.Enabled) { e.Graphics.DrawString(drawText, this.Font, this.ForeBrush, textRect, this.StringFormat); } else { using (SolidBrush brush = new SolidBrush(SystemPens.GrayText.Color)) { e.Graphics.DrawString(drawText, this.Font, brush, textRect, this.StringFormat); } } } //cal needsize CalColumnHeaderNeedWidth(e.Graphics, e.Column, drawText, this.Font, this.StringFormat, imageRect.Width + arrowRect.Width); this.StringFormat.Alignment = old; }
/// <summary> /// 重绘 /// </summary> /// <param name="e">A PaintHeaderEventArgs that contains the event data</param> protected override void OnPaint(I3PaintColumnHeaderEventArgs e) { base.OnPaint(e); if (e.Column == null) { return; } Rectangle textRect = this.ClientRectangle; Rectangle imageRect = Rectangle.Empty; //绘制image if (e.Column.HeaderImage != null) { //计算图标显示区域 imageRect = this.CalcImageRect(); //重置文本显示区域的值 textRect.Width -= imageRect.Width; textRect.X += imageRect.Width; //如果图标显示在右边,重置图标显示区域、文本显示区域的值 if (e.Column.HeaderImageOnRight) { imageRect.X = this.ClientRectangle.Right - imageRect.Width; textRect.X = this.ClientRectangle.X; } //VisualStylesEnabled=true且列头按下时,图标显示区域向下、向右各移动1像素 if (!I3ThemeManager.VisualStylesEnabled && e.Column.ColumnState == I3ColumnState.Pressed) { imageRect.X += 1; imageRect.Y += 1; } //绘制图像 this.DrawColumnHeaderImage(e.Graphics, e.Column.HeaderImage, imageRect, e.Column.Enabled); } //VisualStylesEnabled=true且列头按下时,文本显示区域向下、向右各移动1像素 if (!I3ThemeManager.VisualStylesEnabled && e.Column.ColumnState == I3ColumnState.Pressed) { textRect.X += 1; textRect.Y += 1; } //画排序标签 Rectangle arrowRect = Rectangle.Empty; if (e.Column.SortOrder != SortOrder.None) { //计算排序标签显示区域 arrowRect = this.CalcSortArrowRect(); arrowRect.X = textRect.Right - arrowRect.Width; textRect.Width -= arrowRect.Width; //绘制排序标签 this.DrawSortArrow(e.Graphics, arrowRect, e.Column.SortOrder, e.Column.Enabled); } //绘制文本 StringAlignment old = this.StringFormat.Alignment; string drawText = e.Column.Caption; if (e.Column.Caption.Length > 0 && textRect.Width > 0) { //计算绘制文本的起始点 switch (e.Column.HeaderAlignment) { case I3ColumnAlignment.Center: this.StringFormat.Alignment = StringAlignment.Center; break; case I3ColumnAlignment.Right: this.StringFormat.Alignment = StringAlignment.Far; break; default: this.StringFormat.Alignment = StringAlignment.Near; break; } //this.StringFormat.Trimming=EllipsisCharacter,指定文本超出范围时的剪切方式为以....替代 int columnIndex = e.Table.ColumnModel.Columns.IndexOf(e.Column); switch (e.Table.ColumnHeaderDisplayMode) { case I3ColumnHeaderDisplayMode.Num: drawText = (columnIndex + 1).ToString(); break; case I3ColumnHeaderDisplayMode.Reference: drawText = I3ReferenceUtil.GetColumnName(columnIndex + 1); break; case I3ColumnHeaderDisplayMode.None: drawText = ""; break; default: break; } if (e.Column.Enabled) { e.Graphics.DrawString(drawText, this.Font, this.ForeBrush, textRect, this.StringFormat); } else { using (SolidBrush brush = new SolidBrush(SystemPens.GrayText.Color)) { e.Graphics.DrawString(drawText, this.Font, brush, textRect, this.StringFormat); } } } //cal needsize CalColumnHeaderNeedWidth(e.Graphics, e.Column, drawText, this.Font, this.StringFormat, imageRect.Width + arrowRect.Width); this.StringFormat.Alignment = old; }