/// <inheritdoc/> protected override void Render(CheckBox control, PaintEventArgs e) { var box_size = e.LogicalToDeviceUnits(GLYPH_SIZE); var glyph_padding = e.LogicalToDeviceUnits(GLYPH_TEXT_PADDING); // Draw the checkbox glyph var y = (control.ScaledHeight - box_size) / 2; var box_bounds = new Rectangle(e.LogicalToDeviceUnits(3), y, box_size, box_size); ControlPaint.DrawCheckBox(e, box_bounds, control.CheckState, !control.Enabled); var text_bounds = new Rectangle(box_bounds.Right + glyph_padding, 0, control.ScaledWidth - box_bounds.Right - glyph_padding, control.ScaledHeight); // Draw the focus rectangle if (control.Selected && control.ShowFocusCues) { var focus_bounds = new Rectangle(box_bounds.Right, 0, text_bounds.Width + glyph_padding, text_bounds.Height); e.Canvas.DrawFocusRectangle(focus_bounds, e.LogicalToDeviceUnits(3)); } // Draw the text if (control.Text.HasValue()) { e.Canvas.DrawText(control.Text, text_bounds, control, ContentAlignment.MiddleLeft); } }
public override void PaintValue(PaintValueEventArgs e) { var val = (bool?)e.Value; ControlPaint.DrawCheckBox(e.Graphics, e.Bounds, (val ?? false) ? ButtonState.Checked : ButtonState.Normal); }
/// <summary> /// Draw the "Owner Draw" toggle image area /// </summary> /// <param name="sender">The sender of the event (the image map or image area in this demo)</param> /// <param name="e">The event arguments</param> private void OwnerDrawOnOff_DrawImage(object sender, DrawImageEventArgs e) { Rectangle r = areaOwnerDrawOnOff.Rectangle; r.Inflate(-2, -2); // Offset the area rectangle by the draw event offset r.Offset(e.ImageOffset.X, e.ImageOffset.Y); if (sender is ImageMap) { ControlPaint.DrawCheckBox(e.Graphics, r.X + 5, r.Y, r.Height, r.Height, ButtonState.Checked); r.X += 5 + r.Height; r.Width -= 5 + r.Height; // Use the image map's font e.Graphics.DrawString("&Image map owner draw ON", imMap.Font, Brushes.Black, r, sfFormat); } else { ControlPaint.DrawCheckBox(e.Graphics, r.X + 5, r.Y, r.Height, r.Height, ButtonState.Normal); r.X += 5 + r.Height; r.Width -= 5 + r.Height; e.Graphics.DrawString("&Image map owner draw OFF", imMap.Font, Brushes.Black, r, sfFormat); // Tell the image map to draw the focus rectangle if this is the focused area. It's false by // default if the area is drawing itself. e.DrawFocus = true; } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); this.AutoSize = false; text = this.Text; if (textX == 100 && textY == 25) { textX = ((this.Width) / 3) + 10; textY = (this.Height / 2) - 1; } //drawing string & filling gradient rectangle Color c1 = Color.FromArgb(color1Transparent, color1); Color c2 = Color.FromArgb(color2Transparent, color2); Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle, c1, c2, angle); Point p = new Point(textX, textY); SolidBrush frcolor = new SolidBrush(this.ForeColor); e.Graphics.FillRectangle(b, ClientRectangle); e.Graphics.DrawString(text, this.Font, frcolor, p); Rectangle rc = new Rectangle(boxlocatx, boxlocaty, boxsize, boxsize); //drawing check box ControlPaint.DrawCheckBox(e.Graphics, rc, this.Checked ? ButtonState.Checked : ButtonState.Normal); b.Dispose(); }
private void List_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var backgroundColor = ThemeColorTable.TextBoxBackgroundColor; //Using item selected here as this looks like a known bug since about 2006, in evidence when the ListView.HideSelection property is set to FALSE. //The only workaround on file is to use e.Item.Selected. if (e.Item.Selected) { // Draw the background and focus rectangle for a selected item. backgroundColor = ThemeColorTable.BackgroundColor; e.Graphics.FillRectangle(new SolidBrush(backgroundColor), e.Bounds); } else { e.Graphics.FillRectangle(new SolidBrush(backgroundColor), e.Bounds); } var textBounds = e.Bounds; if (CheckBoxes && e.ColumnIndex == 0) { Size cbSize = CalculateCheckBoxSize(e.SubItem); int top = e.Bounds.Top + (int)((e.Bounds.Height - cbSize.Height) / 2d); Rectangle cbBounds = new Rectangle(new Point(e.Bounds.X + 1, top), cbSize); ControlPaint.DrawCheckBox(e.Graphics, cbBounds, (e.Item.Checked ? ButtonState.Checked : ButtonState.Normal) | ButtonState.Flat); textBounds.X = textBounds.X + cbSize.Width + 1; } TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.Item.Font, textBounds, ThemeColorTable.ForeColor, backgroundColor, TextFormatFlags.VerticalCenter); }
private void List_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var backgroundColor = ThemeColorTable.TextBoxBackgroundColor; if ((e.ItemState & ListViewItemStates.Selected) != 0) { // Draw the background and focus rectangle for a selected item. backgroundColor = ThemeColorTable.BackgroundColor; e.Graphics.FillRectangle(new SolidBrush(backgroundColor), e.Bounds); } else { e.Graphics.FillRectangle(new SolidBrush(backgroundColor), e.Bounds); } var textBounds = e.Bounds; if (CheckBoxes && e.ColumnIndex == 0) { Size cbSize = CalculateCheckBoxSize(e.SubItem); int top = e.Bounds.Top + (int)((e.Bounds.Height - cbSize.Height) / 2d); Rectangle cbBounds = new Rectangle(new Point(e.Bounds.X + 1, top), cbSize); ControlPaint.DrawCheckBox(e.Graphics, cbBounds, (e.Item.Checked ? ButtonState.Checked : ButtonState.Normal) | ButtonState.Flat); textBounds.X = textBounds.X + cbSize.Width + 1; } TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.Item.Font, textBounds, ThemeColorTable.ForeColor, backgroundColor, TextFormatFlags.VerticalCenter); }
public override bool RefreshView() { this.RefreshSize(); //如果是选择打印,则判断是否在范围之内 if (this.IsNeedPrint()) { Rectangle r = this.Bounds; OwnerDocument.View.Graph.DrawString(" " + this.Name, this.Font, Brushes.Black, r, strFormat); Graphics g = this.OwnerDocument.View.Graph; r.Width = 15; r.Height = 15; r.Offset(2, 0); if (this.Checked) { ControlPaint.DrawCheckBox(g, r, ButtonState.Checked); } else { ControlPaint.DrawCheckBox(g, r, ButtonState.Normal); } } return(true); //return base.RefreshView(); }
protected override void OnDraw(GraphicsCache graphics, RectangleF area) { ButtonState state; if (Style == ControlDrawStyle.Disabled) { state = ButtonState.Inactive; } else if (Style == ControlDrawStyle.Pressed) { state = ButtonState.Pushed; } else if (Style == ControlDrawStyle.Hot) { state = ButtonState.Normal; } else { state = ButtonState.Normal; } if (CheckBoxState == CheckBoxState.Checked) { state |= ButtonState.Checked; } ControlPaint.DrawCheckBox(graphics.Graphics, Rectangle.Round(area), state); }
private void Form5_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(10, 10, 20, 20), ButtonState.Normal); ControlPaint.DrawComboButton(e.Graphics, new Rectangle(10, 40, 20, 20), ButtonState.Pushed); // ControlPaint.FillReversibleRectangle(new Rectangle(10, 40, 200, 200),Color.Red); ControlPaint.DrawLockedFrame(e.Graphics, new Rectangle(30, 40, 20, 20), true); }
void listViewPalette_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { int fontColor, backColor; if (!listViewPalette.SelectedIndices.Contains(e.ItemIndex)) { fontColor = e.SubItem.ForeColor.ToArgb(); backColor = e.SubItem.BackColor.ToArgb(); } else { fontColor = SystemColors.HighlightText.ToArgb(); backColor = SystemColors.Highlight.ToArgb(); } switch (e.ColumnIndex) { case ColumnIndexChecked: e.Graphics.FillRectangle(GetBrush(backColor), e.Bounds); var rect = e.Bounds; rect.Width = Math.Min(15, e.Bounds.Width); rect.Height = Math.Min(15, e.Bounds.Height); rect.X += (e.Bounds.Width - rect.Width) / 2; rect.Y += (e.Bounds.Height - rect.Height) / 2; ControlPaint.DrawCheckBox(e.Graphics, rect, (e.Item.Checked ? ButtonState.Checked : ButtonState.Normal) | ButtonState.Flat); break; case ColumnIndexSymbol: e.Graphics.FillRectangle(GetBrush(backColor), e.Bounds); var size = Math.Min(e.Bounds.Height, e.Bounds.Width); var image = size >= 2 ? Controller.GetSymbolImage(e.SubItem.Text[0], size, fontColor, backColor) : null; if (image != null) { var bitmap = image.ToBitmap(); var dx = e.Bounds.Left + (e.Bounds.Width - bitmap.Size.Width) / 2; var dy = e.Bounds.Top + (e.Bounds.Height - bitmap.Size.Height) / 2; e.Graphics.DrawImage(bitmap, dx, dy); bitmap.Dispose(); } break; case ColumnIndexCode: e.DrawDefault = true; break; case ColumnIndexColor: e.Graphics.FillRectangle(GetBrush(e.SubItem.BackColor.ToArgb()), e.Bounds); break; case ColumnIndexCount: e.DrawDefault = true; break; } }
/// <summary> /// Owner drawing listview item. /// </summary> protected void OnDrawItem(DrawItemEventArgs e, PluginListItem item) { e.DrawBackground(); // IsRunnning bitmap const int imageWidth = 16 + 3; if (imageList == null) { imageList = ((PluginDialog)Parent).ImageList; } if (imageList != null) { int imageIndex = item.PluginInfo.IsCurrentlyLoaded ? 0 : 1; imageList.Draw(e.Graphics, e.Bounds.Left + 2, e.Bounds.Top + 1, imageIndex); } // Name Rectangle bounds = Rectangle.FromLTRB(e.Bounds.Left + imageWidth, e.Bounds.Top, e.Bounds.Left + Columns[0].Width, e.Bounds.Bottom); using (Brush brush = new SolidBrush(e.ForeColor)) e.Graphics.DrawString(item.Name, e.Font, brush, bounds); // Check box (Load at startup) bounds = Rectangle.FromLTRB(bounds.Right + 1, bounds.Top, bounds.Right + Columns[1].Width + 1, bounds.Bottom - 1); ButtonState state = item.PluginInfo.IsLoadedAtStartup ? ButtonState.Checked : ButtonState.Normal; ControlPaint.DrawCheckBox(e.Graphics, bounds, state); }
public override void PaintValue(PaintValueEventArgs e) { var context = e.Context; bool check = Convert.ToBoolean(context.PropertyDescriptor.GetValue(context.Instance)); ControlPaint.DrawCheckBox(e.Graphics, e.Bounds, check?ButtonState.Checked : ButtonState.Normal); }
private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { if (e.RowIndex > -1) { int checkBoxColumnIndex = this.yourCheckBoxColumn.Index; var checkCell = (DataGridViewCheckBoxCell)this.dataGridView[checkBoxColumnIndex, e.RowIndex]; var bounds = this.dataGridView.GetCellDisplayRectangle(checkBoxColumnIndex, e.RowIndex, false); // i was drawing a disabled checkbox if i had set the cell to read only if (checkCell.ReadOnly) { const int CheckBoxWidth = 16; const int CheckBoxHeight = 16; // not taking into consideration any cell style paddings bounds.X += (bounds.Width - CheckBoxWidth) / 2; bounds.Y += (bounds.Height - CheckBoxHeight) / 2; bounds.Width = CheckBoxWidth; bounds.Height = CheckBoxHeight; if (VisualStyleRenderer.IsSupported) { // the typical way the checkbox will be drawn DisabledCheckBoxRenderer.DrawBackground(e.Graphics, bounds); } else { // this method is only drawn if the visual styles of the application // are turned off (this is for full support) ControlPaint.DrawCheckBox(e.Graphics, bounds, ButtonState.Inactive); } } } }
protected void DrawCheckBox(PaintEventArgs e, LayoutData layout) { Graphics g = e.Graphics; ButtonState style = GetState(); if (Control.CheckState == CheckState.Indeterminate) { if (Application.RenderWithVisualStyles) { CheckBoxRenderer.DrawCheckBox(g, new Point(layout.checkBounds.Left, layout.checkBounds.Top), CheckBoxRenderer.ConvertFromButtonState(style, true, Control.MouseIsOver), Control.HandleInternal); } else { ControlPaint.DrawMixedCheckBox(g, layout.checkBounds, style); } } else { if (Application.RenderWithVisualStyles) { CheckBoxRenderer.DrawCheckBox(g, new Point(layout.checkBounds.Left, layout.checkBounds.Top), CheckBoxRenderer.ConvertFromButtonState(style, false, Control.MouseIsOver), Control.HandleInternal); } else { ControlPaint.DrawCheckBox(g, layout.checkBounds, style); } } }
public void DrawCheckBox(Graphics g, Rectangle rc, ButtonState state) { if (IsAppThemed) { /* * ThemePartState partState = GetCheckBoxPart(state); * if(partState != null) * { * Rectangle rcClip = new Rectangle((int)g.ClipBounds.Left, (int)g.ClipBounds.Top, (int)g.ClipBounds.Width, (int)g.ClipBounds.Height); * try * { * partState.DrawBackground(g, rc, rcClip); * } * catch(Exception ex) * { * Trace.WriteLine("Failed to DrawCheckBox: " + ex.Message); * } * } * else * ControlPaint.DrawCheckBox(g, rc, state); */ } else { ControlPaint.DrawCheckBox(g, rc, state); } }
/// <summary> /// Draws the check box at the given location and of the size specified by CheckBoxSize</summary> /// <param name="node">The node that the check box is to be drawn for. The HasCheck property /// is assumed to be true.</param> /// <param name="g">The current GDI+ graphics object</param> /// <param name="x">The x-coordinate of the upper-left corner of the check box</param> /// <param name="y">The y-coordinate of the upper-left corner of the check box</param> public virtual void DrawCheckBox(TreeControl.Node node, Graphics g, int x, int y) { Rectangle bounds = new Rectangle(x, y, CheckBoxSize.Width, CheckBoxSize.Height); if (node.CheckState == CheckState.Indeterminate) { // draw indeterminate state. Brush fillBrush = SystemBrushes.Window; Brush fillBrush2 = node.CheckBoxEnabled ? SystemBrushes.ControlText : SystemBrushes.GrayText; Pen borderPen = node.CheckBoxEnabled ? SystemPens.ControlDark : SystemPens.InactiveBorder; var rect = Rectangle.Inflate(bounds, -1, -1); g.FillRectangle(fillBrush, rect); var rect2 = Rectangle.Inflate(bounds, -4, -4); g.FillRectangle(fillBrush2, rect2); g.DrawRectangle(borderPen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1); } else { var buttonState = ButtonState.Flat; if (node.CheckState == CheckState.Checked) { buttonState |= ButtonState.Checked; } if (!node.CheckBoxEnabled) { buttonState |= ButtonState.Inactive; } ControlPaint.DrawCheckBox(g, bounds, buttonState); } }
protected override void OnPaint(PaintEventArgs pevent) { //Draw background using (SolidBrush b = new SolidBrush(this.BackColor)) { pevent.Graphics.FillRectangle(b, this.ClientRectangle); } //Draw the checkbox ControlPaint.DrawCheckBox(pevent.Graphics, new Rectangle(1, 1, 16, 16), this.Checked ? ButtonState.Checked : ButtonState.Normal); //Measure the base string Font f = this.Font; SizeF s1 = pevent.Graphics.MeasureString("Max Parameters on set ", f); Rectangle r1 = new Rectangle(18, 1, s1.Width, this.ClientRectangle.Height - 2); //Create string format using (StringFormat sf = new StringFormat()) { sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; sf.Trimming = StringTrimming.None; //Draw base string pevent.Graphics.DrawString("Max Parameters on set ", f, Brushes.Black, r1, sf); //Draw secondary string, based on check state if (this.Checked) { SizeF s2 = pevent.Graphics.MeasureString("ON", f); Rectangle r2 = new Rectangle(r1.Right, 1, s2.Width, this.ClientRectangle.Height - 2); pevent.Graphics.DrawString("ON", f, Brushes.Green, r2, sf); } else { SizeF s2 = pevent.Graphics.MeasureString("OFF", f); Rectangle r2 = new Rectangle(r1.Right, 1, s2.Width, this.ClientRectangle.Height - 2); pevent.Graphics.DrawString("OFF", f, Brushes.Red, r2, sf); } } }
/// <summary> /// 绘制 CheckBox。 /// </summary> /// <param name="graphics"></param> /// <param name="rect"></param> /// <param name="checked"></param> /// <param name="mixed"></param> /// <param name="enabled"></param> public virtual void DrawCheckbox(Graphics graphics, Rectangle rect, bool @checked, bool mixed, bool enabled) { if (Application.RenderWithVisualStyles) { var element = GetCheckVisualStyleElement(@checked, mixed, enabled); if (element != null && VisualStyleRenderer.IsElementDefined(element)) { new VisualStyleRenderer(element).DrawBackground(graphics, rect); return; } } var bstate = ButtonState.Flat; if (@checked) { bstate |= ButtonState.Checked; } if (!enabled) { bstate |= ButtonState.Inactive; } ControlPaint.DrawCheckBox(graphics, rect, bstate); if (mixed) { var r = rect; r.Inflate(-4, -4); graphics.FillRectangle(Brushes.LightGray, r); } }
public virtual void DrawCheckBox(Graphics graphics, Control control, Rectangle buttonRect, bool drawChecked, bool drawEnabled) { if (Rectangle.Intersect(buttonRect, Rectangle.Round(graphics.ClipBounds)).IsEmpty) { return; } if (ThemeRenderer.Enabled) { int state = (drawEnabled ? (drawChecked ? ThemeButton.CheckBoxCheckedNormal : ThemeButton.CheckBoxUncheckedNormal) : (drawChecked ? ThemeButton.CheckBoxCheckedDisabled : ThemeButton.CheckBoxUncheckedDisabled)); ThemeButton.CheckBox.Draw(graphics, state, buttonRect); } else { ButtonState state = ButtonState.Normal; if (drawChecked) { state |= ButtonState.Checked; } if (!drawEnabled) { state |= ButtonState.Inactive; } ControlPaint.DrawCheckBox(graphics, buttonRect, state); } }
private void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { // check that we are in a header cell! if (e.RowIndex == -1 && e.ColumnIndex > 0) { e.PaintBackground(e.ClipBounds, true); Rectangle rect = MatrixDataGridView.GetColumnDisplayRectangle(e.ColumnIndex, true); Size titleSize = TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font); int offset = 4; if (MatrixDataGridView.ColumnHeadersHeight < titleSize.Width + 2 * offset) { MatrixDataGridView.ColumnHeadersHeight = titleSize.Width + 2 * offset; } e.Graphics.TranslateTransform(1, titleSize.Width); e.Graphics.RotateTransform(-90.0f); e.Graphics.DrawString(e.Value.ToString(), MatrixDataGridView.Font, Brushes.Black, new PointF(rect.Y - (MatrixDataGridView.ColumnHeadersHeight - titleSize.Width - offset), rect.X)); e.Graphics.RotateTransform(90.0f); e.Graphics.TranslateTransform(-1, -titleSize.Width); e.Handled = true; } if (e.RowIndex != -1 && e.ColumnIndex > 0) { var state = (ProjectDependency)e.Value; /*if (state == ProjectDependency.Invalid) * e.CellStyle.BackColor = Color.Silver;*/ e.PaintBackground(e.ClipBounds, true); Rectangle rect = MatrixDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); var CheckBoxRegion = new Rectangle(rect.X + box_offset, rect.Y + box_offset, box_size, box_size); switch (state) { case ProjectDependency.None: ControlPaint.DrawCheckBox(e.Graphics, CheckBoxRegion, ButtonState.Normal); break; case ProjectDependency.Direct: ControlPaint.DrawCheckBox(e.Graphics, CheckBoxRegion, ButtonState.Checked); break; case ProjectDependency.Indirect: ControlPaint.DrawCheckBox(e.Graphics, CheckBoxRegion, ButtonState.Checked | ButtonState.Inactive); break; case ProjectDependency.Invalid: ControlPaint.DrawCheckBox(e.Graphics, CheckBoxRegion, ButtonState.Inactive); break; } e.Handled = true; } }
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); graphics.FillRectangle(new SolidBrush(cellStyle.BackColor), cellBounds); checkBoxRegion = new Rectangle( cellBounds.Location.X + 1, cellBounds.Location.Y + 2, 25, cellBounds.Size.Height - 4); if (this.checkAll) { ControlPaint.DrawCheckBox(graphics, checkBoxRegion, ButtonState.Checked); } else { ControlPaint.DrawCheckBox(graphics, checkBoxRegion, ButtonState.Normal); } Rectangle normalRegion = new Rectangle( cellBounds.Location.X + 1 + 25, cellBounds.Location.Y, cellBounds.Size.Width - 26, cellBounds.Size.Height); graphics.DrawString(value.ToString(), cellStyle.Font, new SolidBrush(cellStyle.ForeColor), normalRegion); }
/// <summary> /// Advanced formatting of cells in the tasks DataGridView. /// </summary> private void GridTasks_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { // Disable the Visible column for the ID field if ((e.ColumnIndex == GridTasks.Columns["visible"].Index) && (e.RowIndex == 0)) { e.PaintBackground(e.CellBounds, true); Rectangle r = e.CellBounds; r.Width = 15; r.Height = 15; r.X += (e.CellBounds.Width / 2) - (r.Width / 2) - 1; r.Y += (e.CellBounds.Height / 2) - (r.Height / 2) - 1; ControlPaint.DrawCheckBox(e.Graphics, r, ButtonState.Inactive | ButtonState.Flat | ButtonState.Checked); e.Handled = true; } if (((e.ColumnIndex == GridTasks.Columns["sort1"].Index) || (e.ColumnIndex == GridTasks.Columns["sort2"].Index)) && (e.RowIndex > -1) && (e.RowIndex != GridTasks.NewRowIndex)) { if (e.State.HasFlag(DataGridViewElementStates.ReadOnly)) { e.PaintBackground(e.CellBounds, true); Rectangle r = e.CellBounds; r.Width = 15; r.Height = 15; r.X += (e.CellBounds.Width / 2) - (r.Width / 2) - 1; r.Y += (e.CellBounds.Height / 2) - (r.Height / 2) - 1; ControlPaint.DrawCheckBox(e.Graphics, r, ButtonState.Inactive | ButtonState.Flat); e.Handled = true; } } }
private void DrawControl(Graphics graphics) { Rectangle rect = GetCheckboxRectangle(); ControlPaint.DrawCheckBox(graphics, rect, this.Checked ? ButtonState.Checked : ButtonState.Normal); int originCaption = _Padding * 2 + CheckSize; Rectangle textRectangle = new Rectangle(originCaption, _Padding, this.Width - originCaption - _Padding * 3, this.Height - _Padding * 2); Brush fontBrush = new SolidBrush(this.ForeColor); StringFormat format = new StringFormat(); switch (this.TextAlign) { case ContentAlignment.TopRight: format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Near; break; case ContentAlignment.TopLeft: format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; break; case ContentAlignment.TopCenter: format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Near; break; case ContentAlignment.MiddleRight: format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Center; break; case ContentAlignment.MiddleLeft: format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; break; case ContentAlignment.MiddleCenter: format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; break; case ContentAlignment.BottomRight: format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Far; break; case ContentAlignment.BottomLeft: format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Far; break; case ContentAlignment.BottomCenter: format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Far; break; } graphics.DrawString(Text, this.Font, fontBrush, textRectangle, format); fontBrush.Dispose(); }
public override void PaintValue(PaintValueEventArgs e) { var rect = e.Bounds; rect.Inflate(1, 1); ControlPaint.DrawCheckBox(e.Graphics, rect, ButtonState.Flat | (((bool)e.Value) ? ButtonState.Checked : ButtonState.Normal)); }
public override void PaintValue(PaintValueEventArgs e) { Rectangle newBounds = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Height, e.Bounds.Height)); ControlPaint.DrawCheckBox(e.Graphics, newBounds, ButtonState.Flat | (Convert.ToBoolean(e.Value) ? ButtonState.Checked : ButtonState.Normal)); e.Graphics.ExcludeClip(e.Bounds); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int num = base.ClientSize.Height - 2; Rectangle rectangle = new Rectangle(new Point(0, 1), new Size(num, num)); ControlPaint.DrawCheckBox(e.Graphics, rectangle, base.Checked ? ButtonState.Checked : ButtonState.Normal); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int h = this.ClientSize.Height - 2; Rectangle rc = new Rectangle(new Point(0, 1), new Size(35, 35)); ControlPaint.DrawCheckBox(e.Graphics, rc, this.Checked ? ButtonState.Checked : ButtonState.Normal); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Size si = SystemInformation.MenuCheckSize; SizeF tsize = e.Graphics.MeasureString(Text, this.Font); _checkRectangle = new Rectangle(new Point(si.Width / 3 + (int)tsize.Width, 0), si); ControlPaint.DrawCheckBox(e.Graphics, _checkRectangle, _checked ? ButtonState.Checked : ButtonState.Normal); }
protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics; g.FillRectangle(new SolidBrush(Color.Transparent), this.ClientRectangle); ControlPaint.DrawCheckBox(g, 1, 1, this.ClientRectangle.Height - 2, this.ClientRectangle.Height - 2, _check ? ButtonState.Checked : ButtonState.Normal); g.DrawString(this.Text, this.Font, new SolidBrush(Color.Black), this.ClientRectangle.Height + 2, (this.Height - g.MeasureString(this.Text, this.Font).Height) / 2); }
private void AddCheckIcon(ButtonState bs) { Bitmap bmp = new Bitmap(16, 16); using (Graphics g = Graphics.FromImage(bmp)) { ControlPaint.DrawCheckBox(g, 0, 0, 16, 16, bs); } myCheckImageList.Images.Add(bmp); }