protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); switch (this.lTipCelula) { case EnumTipCelula.Vid: break; case EnumTipCelula.Text: break; case EnumTipCelula.Lista: ComboBoxRenderer.DrawDropDownButton(graphics, clipBounds, System.Windows.Forms.VisualStyles.ComboBoxState.Normal); break; case EnumTipCelula.Bifa: System.Windows.Forms.VisualStyles.CheckBoxState StareBifa = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; if (this.Value != null && Convert.ToBoolean(this.Value)) { StareBifa = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; } CheckBoxRenderer.DrawCheckBox(graphics, clipBounds.Location, StareBifa); break; case EnumTipCelula.Buton: break; default: break; } }
protected override void OnDrawItem(DrawItemEventArgs e) { string s = Items[e.Index].ToString(); if (_disabledItems.Contains(s) || _disabledIndexes.Contains(e.Index)) { System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled; Size glyphSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state); CheckBoxRenderer.DrawCheckBox( e.Graphics, new Point(e.Bounds.X + 1, e.Bounds.Y + 1), // add one pixel to align the check gliph properly new Rectangle( new Point(e.Bounds.X + glyphSize.Width + 3, e.Bounds.Y), // add three pixels to align text properly new Size(e.Bounds.Width - glyphSize.Width, e.Bounds.Height) ), s, this.Font, TextFormatFlags.Left, // text is centered by default false, state ); } else { base.OnDrawItem(e); } }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); Point p = new Point(); Size s = CheckBoxRenderer.GetGlyphSize(graphics, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); p.X = cellBounds.Location.X + (cellBounds.Width / 2) - (s.Width / 2); p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2); _cellLocation = cellBounds.Location; checkBoxLocation = p; checkBoxSize = s; if (_checked) _cbState = System.Windows.Forms.VisualStyles. CheckBoxState.CheckedNormal; else _cbState = System.Windows.Forms.VisualStyles. CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox (graphics, checkBoxLocation, _cbState); }
private System.Windows.Forms.VisualStyles.CheckBoxState GetCheckBoxState() { System.Windows.Forms.VisualStyles.CheckBoxState ret = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; if (!this.Enabled) { ret = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled; } else if (pressed) { ret = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedPressed; } else if (hot) { ret = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot; } if (this.Checked) { ret += 4; } else if (this.CheckState == System.Windows.Forms.CheckState.Indeterminate) { ret += 8; } return(ret); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); Point p = new Point(); Size s = CheckBoxRenderer.GetGlyphSize(graphics, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); p.X = cellBounds.Location.X + 3; p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2); _cellLocation = cellBounds.Location; checkBoxLocation = p; checkBoxSize = s; if (_checked) { _cbState = System.Windows.Forms.VisualStyles. CheckBoxState.CheckedNormal; } else { _cbState = System.Windows.Forms.VisualStyles. CheckBoxState.UncheckedNormal; } CheckBoxRenderer.DrawCheckBox(graphics, checkBoxLocation, _cbState); }
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawDefault = true; //Draw a checkbox if device is connected System.Windows.Forms.VisualStyles.CheckBoxState chkState = (e.Item.Checked == true) ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; Size chkSize = System.Windows.Forms.CheckBoxRenderer.GetGlyphSize(e.Graphics, chkState); System.Windows.Forms.CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.X + 10, ((ListView)sender).LargeImageList.ImageSize.Height - chkSize.Height), chkState); }
private Bitmap drawCheckBox(CheckedState state) { Bitmap bmp = new Bitmap(16, 16); Graphics g = Graphics.FromImage(bmp); System.Windows.Forms.VisualStyles.CheckBoxState boxState = state == CheckedState.Unchecked ? System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal : (state == CheckedState.Checked ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal); CheckBoxRenderer.DrawCheckBox(Graphics.FromImage(bmp), new Point(0, 1), boxState); return(bmp); }
private void InitCheckBox(CheckBoxState state) { if (checkBoxImages != null && checkBoxImages.ContainsKey(state)) { return; } if (checkBoxImages == null) { checkBoxImages = new Dictionary <CheckBoxState, Bitmap>(); } Bitmap image = new Bitmap(CheckBoxSize.Width, CheckBoxSize.Height); using (Graphics checkBoxGraphics = Graphics.FromImage(image)) { System.Windows.Forms.VisualStyles.CheckBoxState vsState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; switch (state) { case CheckBoxState.CheckedDisabled: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedDisabled; break; case CheckBoxState.CheckedHot: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot; break; case CheckBoxState.CheckedNormal: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; break; case CheckBoxState.CheckedPressed: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedPressed; break; case CheckBoxState.MixedDisabled: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.MixedDisabled; break; case CheckBoxState.MixedHot: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.MixedHot; break; case CheckBoxState.MixedNormal: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal; break; case CheckBoxState.MixedPressed: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.MixedPressed; break; case CheckBoxState.UncheckedDisabled: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled; break; case CheckBoxState.UncheckedHot: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot; break; case CheckBoxState.UncheckedNormal: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; break; case CheckBoxState.UncheckedPressed: vsState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedPressed; break; } CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, vsState); } checkBoxImages[state] = image; }
protected void RenderCheckBoxHover(Graphics graphics) { switch (m_checkedAllState) { case CheckState.Unchecked: this.m_checkboxState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot; break; case CheckState.Indeterminate: this.m_checkboxState = System.Windows.Forms.VisualStyles.CheckBoxState.MixedHot; break; case CheckState.Checked: this.m_checkboxState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot; break; } }
private void frkCheckBox_Paint(object sender, PaintEventArgs e) { if (frkCheckBox.CheckState == CheckState.Indeterminate) { System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(frkCheckBox.ClientRectangle.Location.X, frkCheckBox.ClientRectangle.Location.Y + 1), state); e.Graphics.DrawString("?", new Font(this.Font.FontFamily, 7.5f, FontStyle.Bold), new SolidBrush(indeterminateColor), new Point(frkCheckBox.ClientRectangle.Location.X + 1, frkCheckBox.ClientRectangle.Location.Y + 1)); } }
/// <summary> /// Override the Paint method to show the disabled checked/unchecked datagridviewcheckboxcell. /// </summary> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (this.enabledValue) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); Rectangle checkBoxArea = cellBounds; Rectangle buttonAdjustment = this.BorderWidths(advancedBorderStyle); checkBoxArea.X += buttonAdjustment.X; checkBoxArea.Y += buttonAdjustment.Y; checkBoxArea.Height -= buttonAdjustment.Height; checkBoxArea.Width -= buttonAdjustment.Width; Point drawInPoint = new Point(cellBounds.X + cellBounds.Width / 2 - 7, cellBounds.Y + cellBounds.Height / 2 - 7); System.Windows.Forms.VisualStyles.CheckBoxState cbState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled; if (!(bool)value) { cbState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled; } else { cbState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedDisabled; } //CheckBoxRenderer.DrawCheckBox(graphics, drawInPoint, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedDisabled); CheckBoxRenderer.DrawCheckBox(graphics, drawInPoint, cbState); } }
// Methods public static bool IsBackgroundPartiallyTransparent(System.Windows.Forms.VisualStyles.CheckBoxState state) { }
protected virtual void OnDrawItem(Object sender, DrawItemEventArgs e) { Int32 zX1 = 0; Pen zPen = null; float zWidth = 0F; string zText = null; Font zFont = null; Color zFore = new Color(); System.Windows.Forms.VisualStyles.CheckBoxState zState = 0; //1 - Exit if (e.Index < 0) { //base.OnDrawItem(this,e); return; } //2 - Grouping if (this.Items[e.Index].ToString().Contains(this.mDividerFormat) & mDividerFormat.Length > 0) { e.DrawBackground(); if (DataSource == null) //TN Engineers { zText = this.Items[e.Index].ToString(); } else { zText = ((System.Data.DataRowView)(this.Items[e.Index]))[this.DisplayMember].ToString(); } zText = this.Items[e.Index].ToString(); zText = " " + zText.Replace(this.mDividerFormat, "") + " "; zFont = new Font(Font, FontStyle.Bold); if (e.BackColor == System.Drawing.SystemColors.Highlight) { zFore = Color.Gainsboro; } else { zFore = this.GroupColour; } zPen = new Pen(zFore); zWidth = e.Graphics.MeasureString(zText, zFont).Width; zX1 = Convert.ToInt32(e.Bounds.Width - zWidth) / 2; e.Graphics.DrawRectangle(zPen, new Rectangle(e.Bounds.X, e.Bounds.Y + e.Bounds.Height / 2, zX1, 1)); e.Graphics.DrawRectangle(zPen, new Rectangle(e.Bounds.Width - zX1, e.Bounds.Y + e.Bounds.Height / 2, e.Bounds.Width, 1)); e.Graphics.DrawString(zText, zFont, new SolidBrush(zFore), zX1, e.Bounds.Top); } else { //3 - ItemBackColor if (mKillEvents2 == 0) { //INSTANT C# NOTE: The following VB 'Select Case' included range-type or non-constant 'Case' expressions and was converted to C# 'if-else' logic: // Select Case true //ORIGINAL LINE: Case System.Convert.ToBoolean(e.State And DrawItemState.Selected) //not used With Krypton if (true == System.Convert.ToBoolean(e.State & DrawItemState.Selected)) { // e.DrawBackground(); } //ORIGINAL LINE: Case e.Index % 2 = 0 else if (true == (e.Index % 2 == 0)) { e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds); } //ORIGINAL LINE: Case Else else { if (_alternateRowColorEnabled) { e.Graphics.FillRectangle(new SolidBrush(_alternateRowColor), e.Bounds); } else { e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds); } } } //4 - ItemText ( _SearchPoint1) if (this.DataSource == null) //TN Engineers { if (true != System.Convert.ToBoolean(e.State & DrawItemState.Selected)) { //not used anymore //e.Graphics.DrawString(this.Items[e.Index].ToString(), Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top); //Using Krypton Text renderer routine DrawItemText(ref e, this.Items[e.Index].ToString()); } } else { if (true != System.Convert.ToBoolean(e.State & DrawItemState.Selected)) { //not used anymore //e.Graphics.DrawString(((System.Data.DataRowView)(this.Items[e.Index]))[this.DisplayMember].ToString(), Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top); //Using Krypton Text renderer routine DrawItemText(ref e, ((System.Data.DataRowView)(this.Items[e.Index]))[this.DisplayMember].ToString()); } } //5 - CheckBox if (mCheckBoxes) { if (System.Convert.ToBoolean(e.State & DrawItemState.Selected)) { if (this.get_ItemsChecks(e.Index) == CheckState.Checked) { zState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot; } else { zState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot; } } else { if (this.get_ItemsChecks(e.Index) == CheckState.Checked) { zState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; } else { zState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; } } zX1 = this.FontHeight; zPen = new Pen(Color.Black, 1F); zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; System.Windows.Forms.CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(e.Bounds.X + e.Bounds.Width - 15, e.Bounds.Y + 1 + ((e.Bounds.Height - 13) / 2)), e.Bounds, "", this.Font, false, zState); } } //6 - Base event //base.OnDrawItem(this,e); }
protected override void OnDrawItem(DrawItemEventArgs e) { Int32 zX1 = 0; Pen zPen = null; float zWidth = 0F; string zText = null; Font zFont = null; Color zFore = new Color(); System.Windows.Forms.VisualStyles.CheckBoxState zState = 0; if (e.Index < 0) { base.OnDrawItem(e); return; //fix for designer error - hope doesnt effect runtime drawing } Rectangle r = e.Bounds; ComboBoxItem item = (ComboBoxItem)this.Items[e.Index]; //NOTE 1st part of if statement draw group item, 2nd draws actual item if (this.Items[e.Index].ToString().Contains(this.mDividerFormat) & mDividerFormat.Length > 0) { //background if (e.Index == SelectedIndex) { e.DrawBackground(); } zText = item.Text;// this.Items[e.Index].ToString(); zText = " " + zText.Replace(this.mDividerFormat, "") + " "; zFont = new Font(Font, FontStyle.Bold); //group item if (e.BackColor == System.Drawing.SystemColors.Highlight) { zFore = Color.Gainsboro; //Color.LightGray 'Color.Silver 'gray colr lets user know that shouldn't be selecting a group item } else { zFore = this.GroupColor; //e.ForeColor } zPen = new Pen(zFore); //draw group zWidth = e.Graphics.MeasureString(zText, zFont).Width; zX1 = Convert.ToInt32(e.Bounds.Width - zWidth) / 2; e.Graphics.DrawRectangle(zPen, new Rectangle(e.Bounds.X, e.Bounds.Y + e.Bounds.Height / 2, zX1, 1)); e.Graphics.DrawRectangle(zPen, new Rectangle(e.Bounds.Width - zX1, e.Bounds.Y + e.Bounds.Height / 2, e.Bounds.Width, 1)); if (item.Image != null) e.Graphics.DrawImage(item.Image, new Rectangle(new Point(item.ImageOffset, r.Height * e.Index), item.ImageSize)); e.Graphics.DrawString(zText, zFont, new SolidBrush(zFore), zX1 + item.ImageOffset + item.ImageSize.Width + 4, r.Height * e.Index); } else { if (mRedrawingUnselected) { if (mIndex % 2 == 0) { e.Graphics.FillRectangle(new SolidBrush(Color.White), mBounds); //e.Bounds)'FIX for wrong bound being passed } else { e.Graphics.FillRectangle(new SolidBrush(mGridColor), mBounds); //e.Bounds) 'FIX for wrong bound being passed } } else { if (e.Index == SelectedIndex) { e.DrawBackground(); } else { if (e.Index % 2 == 0) { e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds); } else { e.Graphics.FillRectangle(new SolidBrush(mGridColor), e.Bounds); } } } //checkbox work if (mCheckBoxes) { if (e.BackColor == System.Drawing.SystemColors.Highlight) { if (this.GetItemsChecks(e.Index)) { zState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot; } else { zState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot; } } else { if (this.GetItemsChecks(e.Index)) { zState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; } else { zState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; } } zX1 = this.FontHeight; /// 2 'variable re-use zPen = new Pen(Color.Black, 1F); zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; //e.Graphics.DrawLine(zPen, e.Bounds.Left, e.Bounds.Top + zX1, e.Bounds.Left + e.Bounds.Width, e.Bounds.Top + zX1) System.Windows.Forms.CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(0, e.Bounds.Y + 1), e.Bounds, "", this.Font, false, zState); } int checkBoxWidth = 0; if (mCheckBoxes) { checkBoxWidth = 20; } int imageWid = this.ItemHeight; if (item.Image != null) { e.Graphics.DrawImage(item.Image, new Rectangle(new Point(item.ImageOffset + checkBoxWidth, r.Height * e.Index), item.ImageSize)); imageWid = item.ImageSize.Width; } //text work e.Graphics.DrawString(item.Text, Font, new SolidBrush(e.ForeColor), new PointF(item.ImageOffset + checkBoxWidth + imageWid + 4, r.Height * e.Index));//this.Items[e.Index].ToString() } //exits here when redrawing unselected if (mRedrawingUnselected) { mRedrawingUnselected = false; } else { //NOTE just seems to work 100% when timer is used in conjunction with .Bound override of old graphics property if (SelectedIndex == e.Index) { mGraphics_t = e.Graphics; mBounds_t = e.Bounds; mIndex_t = e.Index; mTimer1 = new Timer(); mTimer1.Interval = 5; mTimer1.Enabled = true; mTimer1.Tick += new EventHandler(mTimer1_Tick); } } base.OnDrawItem(e); }
void ForwardListView_DrawItem(object sender, DrawListViewItemEventArgs e) { if (this.View == View.Tile) { int checkBoxAreaWidth = CHECKBOX_PADDING + CHECKBOX_SIZE + CHECKBOX_PADDING; System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(e.Bounds.X + checkBoxAreaWidth, e.Bounds.Top, e.Bounds.Width - checkBoxAreaWidth, e.Bounds.Height); // update information DestinationBase fc = (DestinationBase)e.Item.Tag; string display = Escape(fc.Display); string address = Escape(fc.AddressDisplay); string additional = Escape(fc.AdditionalDisplayInfo); string tooltip = String.Format("{0}\r\n{1}{2}", fc.Display, fc.AddressDisplay, (!String.IsNullOrEmpty(fc.AdditionalDisplayInfo) ? String.Format("\r\n{0}", fc.AdditionalDisplayInfo) : null)); e.Item.ToolTipText = tooltip; // NOTE: dont set the .Text or .SubItem properties here - it causes an erratic exception bool drawEnabled = ShouldDrawEnabled(fc); bool selected = this.SelectedIndices.Contains(e.ItemIndex); // draw the background for selected states if (drawEnabled && selected) { e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds); } else { e.DrawBackground(); } // draw the focus rectangle if (selected) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds); } // draw icon int newX = bounds.X; DestinationBase db = e.Item.Tag as DestinationBase; if (db != null) { System.Drawing.Image img = db.GetIcon(); // size if (img.Width > IMAGE_SIZE) { System.Drawing.Image resized = new System.Drawing.Bitmap(IMAGE_SIZE, IMAGE_SIZE); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(resized); using (g) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(img, 0, 0, IMAGE_SIZE, IMAGE_SIZE); } img = resized; } if (img != null) { int x = bounds.X; int y = bounds.Top; if (drawEnabled) { e.Graphics.DrawImage(img, new System.Drawing.Rectangle(x, y, img.Width, img.Height)); } else { ControlPaint.DrawImageDisabled(e.Graphics, img, x, y, System.Drawing.Color.Transparent); } newX += IMAGE_SIZE + this.Margin.Right; } } // offset the text vertically a bit so it lines up with the icon better System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, bounds.Top, bounds.Right - newX, e.Item.Font.Height); rect.Offset(0, 4); // draw main text System.Drawing.Color textColor = (drawEnabled ? e.Item.ForeColor : System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb())); System.Drawing.StringFormat sf = new System.Drawing.StringFormat(); sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip; System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(textColor); using (textBrush) { e.Graphics.DrawString(display, e.Item.Font, textBrush, rect, sf); } // draw additional information text System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb()); System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor); using (subBrush) { // draw address display (line 2) rect.Offset(0, e.Item.Font.Height); e.Graphics.DrawString(address, e.Item.Font, subBrush, rect, sf); // draw additional display (line 3) rect.Offset(0, e.Item.Font.Height); e.Graphics.DrawString(additional, e.Item.Font, subBrush, rect, sf); } // draw checkbox System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; if (fc.Enabled) { state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; } else { state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; } CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(e.Bounds.Left + CHECKBOX_PADDING, e.Bounds.Top + CHECKBOX_PADDING), state); } else { e.DrawDefault = true; } }
//绘制列头checkbox protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); Point point = new Point(); Size size = CheckBoxRenderer.GetGlyphSize(graphics, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); point.X = cellBounds.Location.X + (cellBounds.Width / 2) - (size.Width / 2) - 1;//列头checkbox的X坐标 point.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (size.Height / 2);//列头checkbox的Y坐标 cellLocation = cellBounds.Location; checkBoxLocation = point; checkBoxSize = size; if (isChecked) state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; else state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(graphics, checkBoxLocation, state); }
public static System.Drawing.Size GetGlyphSize(System.Drawing.Graphics g, System.Windows.Forms.VisualStyles.CheckBoxState state) { }
public static void DrawCheckBox(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string checkBoxText, System.Drawing.Font font, TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state) { }
public static void DrawCheckBox(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Windows.Forms.VisualStyles.CheckBoxState state) { }