protected virtual void OnDrawFirstSubItem(DrawListViewSubItemEventArgs e, Graphics g) { TextFormatFlags flags = GetFormatFlags(e.Header.TextAlign); Rectangle rect = e.Bounds; Image img = null; Size imgSize = Size.Empty; Rectangle checkBoxRect = new Rectangle(rect.X, rect.Y, 0, 0); Rectangle imgRect = checkBoxRect; Rectangle textRect = rect; int offset = 2; if (e.Item.ListView.CheckBoxes) { checkBoxRect.X += offset * 2; checkBoxRect.Y = rect.Top + (rect.Height - this._CheckBoxSize.Height) / 2; checkBoxRect.Width = this._CheckBoxSize.Width; checkBoxRect.Height = this._CheckBoxSize.Height; imgRect.X = checkBoxRect.Right; textRect.X = checkBoxRect.Right; textRect.Width -= this._CheckBoxSize.Width - offset * 2; GDIHelper.DrawCheckBox(g, new RoundRectangle(checkBoxRect, 1)); if (e.Item.Checked) { GDIHelper.DrawCheckedStateByImage(g, checkBoxRect); } } if (e.Item.ImageList != null && e.Item.ImageIndex >= 0) { img = e.Item.ImageList.Images[e.Item.ImageIndex]; imgSize = e.Item.ImageList.ImageSize; imgRect.X += offset * 3; imgRect.Y = rect.Y + offset; int width = rect.Height - offset * 2; imgRect.Width = width; imgRect.Height = width; textRect.X = imgRect.Right; textRect.Width -= width - offset * 2; GDIHelper.DrawImage(g, imgRect, img, imgSize); } textRect.X += offset; textRect.Width -= offset * 2; Color c = (e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected ? Color.White : e.SubItem.ForeColor; TextRenderer.DrawText(g, e.SubItem.Text, this._Font, textRect, c, flags); }
/// <summary> /// 绘制复选框和内容. /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-07-29 15:44. private void DrawContent(Graphics g) { GDIHelper.InitializeGraphics(g); int w = this.Width; int h = this.Height; Rectangle boxRect = new Rectangle(this._Margin, h / 2 - this._BoxSize.Height / 2, this._BoxSize.Width, this._BoxSize.Height); Size textSize = g.MeasureString(this.Text, this.Font).ToSize(); Rectangle textRect = new Rectangle(); textRect.X = boxRect.Right + this._Margin; textRect.Y = this._Margin; textRect.Height = this.Height - this._Margin * 2; textRect.Width = textSize.Width; RoundRectangle roundRect = new RoundRectangle(boxRect, this._CornerRadius); switch (this._ControlState) { case EnumControlState.HeightLight: //GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor); GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor); GDIHelper.DrawPathInnerBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First); break; default: GDIHelper.DrawCheckBox(g, roundRect); break; } Color c = base.Enabled ? this.ForeColor : SkinManager.CurrentSkin.UselessColor; //TextRenderer.DrawText(g, this.Text, this.Font, textRect, c, TextFormatFlags.Default); GDIHelper.DrawImageAndString(g, textRect, null, Size.Empty, this.Text, this.Font, c); switch (this.CheckState) { case System.Windows.Forms.CheckState.Checked: GDIHelper.DrawCheckedStateByImage(g, boxRect); break; case System.Windows.Forms.CheckState.Indeterminate: Rectangle innerRect = boxRect; innerRect.Inflate(-3, -3); Color cc = Color.FromArgb(46, 117, 35); GDIHelper.FillRectangle(g, new RoundRectangle(innerRect, this._CornerRadius), cc); break; } }
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); Rectangle rect = e.ImageRectangle; if (toolStrip is ToolStripDropDown) { rect.Width -= 2; rect.Height -= 2; RoundRectangle roundRect = new RoundRectangle(rect, 1); GDIHelper.DrawCheckBox(g, roundRect); GDIHelper.DrawCheckedStateByImage(g, rect); } else { base.OnRenderItemCheck(e); } }