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); } } }
protected override void OnOwnerDraw(Graphics g) { CheckBox checkBox = base.HostControl as CheckBox; System.Drawing.ContentAlignment checkAlign = checkBox.CheckAlign; CheckBoxState state = checkBox.Focused ? CheckBoxState.MixedHot : CheckBoxState.MixedNormal; Size glyphSize = CheckBoxRenderer.GetGlyphSize(g, state); Rectangle rectangle = base.CalculateCheckBounds(checkAlign, glyphSize); if (LayoutHelper.IsRightToLeft(base.HostControl)) { rectangle.Offset(-1, 0); } if (base["Checked"] == 3) { int num = LayoutHelper.IsRightToLeft(base.HostControl) ? 12 : 8; Rectangle targetRect = new Rectangle(rectangle.Left + rectangle.Width - num, rectangle.Top, 8, 8); Color color = checkBox.Enabled ? checkBox.BackColor : SystemColors.Control; using (new SolidBrush(color)) { g.DrawIcon(Icons.LockIcon, targetRect); } checkBox.Enabled = false; return; } if (Application.RenderWithVisualStyles) { CheckBoxRenderer.DrawCheckBox(g, rectangle.Location, state); return; } ControlPaint.DrawMixedCheckBox(g, rectangle, ButtonState.Checked); }
/// <summary> /// Draws a checkbox in the desired state and style /// </summary> /// <param name="bounds">boundaries of the checkbox</param> /// <param name="gx">graphics context object</param> /// <param name="buttonState">state to draw the checkbox in</param> private void DrawCheckbox(Rectangle bounds, Graphics gx, ButtonState buttonState) { // if we don't have custom images, or no imagelist, draw default images if (!this.useCustomImages || (this.useCustomImages && null == this.ImageList)) { ControlPaint.DrawMixedCheckBox(gx, bounds, buttonState); //System.Windows.Forms.VisualStyles.VisualStyleRenderer render = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox.UncheckedNormal); //if (buttonState == ButtonState.Pushed) // render.DrawImage(gx, bounds, ImageList, IndeterminateImageIndex); //else if (buttonState == ButtonState.Checked) // render.DrawImage(gx, bounds, ImageList, CheckedImageIndex); return; } // get the right image index int imageIndex = -1; if ((buttonState & ButtonState.Normal) == ButtonState.Normal) { imageIndex = this.indexUnchecked; } if ((buttonState & ButtonState.Checked) == ButtonState.Checked) { imageIndex = this.indexChecked; } if ((buttonState & ButtonState.Pushed) == ButtonState.Pushed) { imageIndex = this.indexIndeterminate; } if (imageIndex > -1 && imageIndex < this.ImageList.Images.Count) { // index is valid so draw the image this.ImageList.Draw(gx, bounds.X, bounds.Y, bounds.Width + 1, bounds.Height + 1, imageIndex); } else { // index is not valid so draw default image ControlPaint.DrawMixedCheckBox(gx, bounds, buttonState); } }
/// <summary> /// Draws a check box in the specified state, on the specified graphics /// surface, and within the specified bounds /// </summary> /// <param name="g">The Graphics to draw on</param> /// <param name="checkRect">The Rectangle that represents the dimensions /// of the check box</param> /// <param name="clipRect">The Rectangle that represents the clipping area</param> /// <param name="state">A CheckBoxStates value that specifies the /// state to draw the check box in</param> public static void DrawCheck(Graphics g, Rectangle checkRect, Rectangle clipRect, CheckBoxStates state) { if (g == null || checkRect.Width <= 0 || checkRect.Height <= 0) { return; } if (ThemeManager.VisualStylesEnabled) { ThemeManager.DrawThemeBackground(g, ThemeClasses.Button, (int)ButtonParts.CheckBox, (int)state, checkRect, clipRect); } else { if (IsMixed(state)) { ControlPaint.DrawMixedCheckBox(g, checkRect, ThemeManager.ConvertCheckBoxStateToButtonState(state)); } else { ControlPaint.DrawCheckBox(g, checkRect, ThemeManager.ConvertCheckBoxStateToButtonState(state)); } } }
/// <summary> /// Draws a checkbox in the desired state and style /// </summary> /// <param name="bounds">boundaries of the checkbox</param> /// <param name="gx">graphics context object</param> /// <param name="buttonState">state to draw the checkbox in</param> private void DrawCheckbox(Rectangle bounds, Graphics gx, ButtonState buttonState) { // if we don't have custom images, or no imagelist, draw default images if (!this.useCustomImages || (this.useCustomImages && null == this.ImageList)) { ControlPaint.DrawMixedCheckBox(gx, bounds, buttonState); return; } // get the right image index int imageIndex = -1; if ((buttonState & ButtonState.Normal) == ButtonState.Normal) { imageIndex = this.indexUnchecked; } if ((buttonState & ButtonState.Checked) == ButtonState.Checked) { imageIndex = this.indexChecked; } if ((buttonState & ButtonState.Pushed) == ButtonState.Pushed) { imageIndex = this.indexIndeterminate; } if (imageIndex > -1 && imageIndex < this.ImageList.Images.Count) { // index is valid so draw the image this.ImageList.Draw(gx, bounds.X, bounds.Y, bounds.Width + 1, bounds.Height + 1, imageIndex); } else { // index is not valid so draw default image ControlPaint.DrawMixedCheckBox(gx, bounds, buttonState); } }
protected override void CreateStateImages() { base.CreateStateImages(); VisualStyleRenderer vsr = null; if (VisualStyleRenderer.IsSupported) { vsr = new VisualStyleRenderer( VisualStyleElement.Button.CheckBox.UncheckedNormal); } var smallIconSize = new Rectangle(0, 0, StateImageList.ImageSize.Width, StateImageList.ImageSize.Height); var bitmap = new Bitmap(StateImageList.ImageSize.Width, StateImageList.ImageSize.Height); using (Graphics graphics = Graphics.FromImage(bitmap)) { // add unchecked checkbox image if (vsr == null) { ControlPaint.DrawCheckBox(graphics, smallIconSize, ButtonState.Normal); } else { vsr.SetParameters(VisualStyleElement.Button.CheckBox.UncheckedNormal); vsr.DrawBackground(graphics, smallIconSize); } StateImageList.Images.Add(bitmap, Color.Transparent); // add checked checkbox image if (vsr == null) { ControlPaint.DrawCheckBox(graphics, smallIconSize, ButtonState.Checked); } else { vsr.SetParameters(VisualStyleElement.Button.CheckBox.CheckedNormal); vsr.DrawBackground(graphics, smallIconSize); } StateImageList.Images.Add(bitmap, Color.Transparent); // add mixed checkbox image if (vsr == null) { ControlPaint.DrawMixedCheckBox(graphics, smallIconSize, ButtonState.Pushed); } else { vsr.SetParameters(VisualStyleElement.Button.CheckBox.MixedNormal); vsr.DrawBackground(graphics, smallIconSize); } StateImageList.Images.Add(bitmap, Color.Transparent); } }
/// <summary> /// Draws a check box in the specified state, on the specified graphics /// surface, and within the specified bounds /// </summary> /// <param name="g">The Graphics to draw on</param> /// <param name="checkRect">The Rectangle that represents the dimensions /// of the check box</param> /// <param name="clipRect">The Rectangle that represents the clipping area</param> /// <param name="state">A CheckBoxState value that specifies the /// state to draw the check box in</param> public static void DrawCheck(Graphics g, Rectangle checkRect, Rectangle clipRect, CheckBoxState state) { if (g == null || checkRect.Width <= 0 || checkRect.Height <= 0) { return; } if (ThemeManager.VisualStylesEnabled) { //ThemeManager.DrawThemeBackground(g, ThemeClasses.Button, (int) ButtonParts.CheckBox, (int) state, checkRect, clipRect); VisualStyleRenderer renderer; switch (state) { case CheckBoxState.CheckedDisabled: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.CheckedDisabled); break; case CheckBoxState.CheckedHot: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.CheckedHot); break; case CheckBoxState.CheckedNormal: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.CheckedNormal); break; case CheckBoxState.CheckedPressed: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.CheckedPressed); break; case CheckBoxState.MixedDisabled: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.MixedDisabled); break; case CheckBoxState.MixedHot: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.MixedHot); break; case CheckBoxState.MixedNormal: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.MixedNormal); break; case CheckBoxState.MixedPressed: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.MixedPressed); break; case CheckBoxState.UncheckedDisabled: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.UncheckedDisabled); break; case CheckBoxState.UncheckedHot: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.UncheckedHot); break; case CheckBoxState.UncheckedPressed: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.UncheckedPressed); break; case CheckBoxState.UncheckedNormal: default: renderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.UncheckedNormal); break; } renderer.DrawBackground(g, checkRect, clipRect); } else { if (IsMixed(state)) { ControlPaint.DrawMixedCheckBox(g, checkRect, ThemeManager.ConvertCheckBoxStateToButtonState(state)); } else { ControlPaint.DrawCheckBox(g, checkRect, ThemeManager.ConvertCheckBoxStateToButtonState(state)); } } }