/// <summary> /// Draws a check box control /// </summary> public override void DrawCheckBox(Graphics graphics, int x, int y, int width, int height, ButtonState state) { // revert to default theme if necessary if (!enableTheme) // && !FlatStyle.System { base.DrawCheckBox(graphics, x, y, width, height, state); return; } CheckBoxStates ctlState = CheckBoxStates.CBS_UNCHECKEDNORMAL; if ((state & ButtonState.Inactive) != 0) { ctlState = CheckBoxStates.CBS_UNCHECKEDDISABLED; if ((state & ButtonState.Checked) != 0) { ctlState = CheckBoxStates.CBS_CHECKEDDISABLED; } } else { if ((state & ButtonState.Checked) != 0) { ctlState = CheckBoxStates.CBS_CHECKEDNORMAL; } } Theme.DrawControl(graphics, "Button", x, y, width, height, (int)ButtonParts.BP_CHECKBOX, (int)ctlState); }
/// <summary> /// Converts the specified CheckBoxStates value to a ButtonState value /// </summary> /// <param name="state">The CheckBoxStates value to be converted</param> /// <returns>A ButtonState value that represents the specified CheckBoxStates /// value</returns> private static ButtonState ConvertCheckBoxStateToButtonState(CheckBoxStates state) { switch (state) { case CheckBoxStates.UncheckedPressed: { return(ButtonState.Pushed); } case CheckBoxStates.UncheckedDisabled: { return(ButtonState.Inactive); } case CheckBoxStates.CheckedNormal: case CheckBoxStates.CheckedHot: { return(ButtonState.Checked); } case CheckBoxStates.CheckedPressed: { return(ButtonState.Checked | ButtonState.Pushed); } case CheckBoxStates.CheckedDisabled: { return(ButtonState.Checked | ButtonState.Inactive); } case CheckBoxStates.MixedNormal: case CheckBoxStates.MixedHot: { return(ButtonState.Checked); } case CheckBoxStates.MixedPressed: { return(ButtonState.Checked | ButtonState.Pushed); } case CheckBoxStates.MixedDisabled: { return(ButtonState.Checked | ButtonState.Inactive); } } return(ButtonState.Normal); }
/// <summary> /// Returns whether the specified CheckBoxStates value is in an /// indeterminate state /// </summary> /// <param name="state">The CheckBoxStates value to be checked</param> /// <returns>true if the specified CheckBoxStates value is in an /// indeterminate state, false otherwise</returns> private static bool IsMixed(CheckBoxStates state) { switch (state) { case CheckBoxStates.MixedNormal: case CheckBoxStates.MixedHot: case CheckBoxStates.MixedPressed: case CheckBoxStates.MixedDisabled: { return(true); } } return(false); }
/// <summary> /// Raises the Paint event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> protected override void OnPaint(PaintCellEventArgs e) { base.OnPaint(e); // don't bother if the Cell is null if (e.Cell == null) { return; } Rectangle checkRect = this.CalcCheckRect(this.LineAlignment, this.Alignment); CheckBoxStates state = this.GetCheckBoxRendererData(e.Cell).CheckState; if (!e.Enabled) { if (e.Cell.CheckState == CheckState.Checked) { state = CheckBoxStates.CheckedDisabled; } else if (e.Cell.CheckState == CheckState.Indeterminate) { state = CheckBoxStates.MixedDisabled; } else // if (e.Cell.CheckState == CheckState.Unchecked) { state = CheckBoxStates.UncheckedDisabled; } } if (e.Table.ColumnModel.Columns[e.Column] is CheckBoxColumn && ((CheckBoxColumn)e.Table.ColumnModel.Columns[e.Column]).CheckStyle != CheckBoxColumnStyle.CheckBox) { // remove any mixed states switch (state) { case CheckBoxStates.MixedNormal: state = CheckBoxStates.CheckedNormal; break; case CheckBoxStates.MixedHot: state = CheckBoxStates.CheckedHot; break; case CheckBoxStates.MixedPressed: state = CheckBoxStates.CheckedPressed; break; case CheckBoxStates.MixedDisabled: state = CheckBoxStates.CheckedDisabled; break; } ThemeManager.DrawRadioButton(e.Graphics, checkRect, (RadioButtonStates)state); } else { ThemeManager.DrawCheck(e.Graphics, checkRect, state); } if (this.DrawText) { string text = e.Cell.Text; if (text != null && text.Length != 0) { Rectangle textRect = this.ClientRectangle; textRect.X += checkRect.Width + 1; textRect.Width -= checkRect.Width + 1; if (e.Enabled) { e.Graphics.DrawString(e.Cell.Text, this.Font, this.ForeBrush, textRect, this.StringFormat); } else { e.Graphics.DrawString(e.Cell.Text, this.Font, this.GrayTextBrush, textRect, this.StringFormat); } } } if (e.Focused && e.Enabled) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
/// <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 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="state">A CheckBoxStates value that specifies the /// state to draw the check box in</param> public static void DrawCheck(Graphics g, Rectangle checkRect, CheckBoxStates state) { ThemeManager.DrawCheck(g, checkRect, checkRect, state); }
/// <summary> /// Initializes a new instance of the ButtonRendererData class with the /// specified CheckBox state /// </summary> /// <param name="checkState">The current state of the Cells CheckBox</param> public CheckBoxRendererData(CheckBoxStates checkState) { this.checkState = checkState; }
/// <summary> /// Returns whether the specified CheckBoxStates value is in an /// indeterminate state /// </summary> /// <param name="state">The CheckBoxStates value to be checked</param> /// <returns>true if the specified CheckBoxStates value is in an /// indeterminate state, false otherwise</returns> private static bool IsMixed(CheckBoxStates state) { switch (state) { case CheckBoxStates.MixedNormal: case CheckBoxStates.MixedHot: case CheckBoxStates.MixedPressed: case CheckBoxStates.MixedDisabled: { return true; } } return false; }
/// <summary> /// Converts the specified CheckBoxStates value to a ButtonState value /// </summary> /// <param name="state">The CheckBoxStates value to be converted</param> /// <returns>A ButtonState value that represents the specified CheckBoxStates /// value</returns> private static ButtonState ConvertCheckBoxStateToButtonState(CheckBoxStates state) { switch (state) { case CheckBoxStates.UncheckedPressed: { return ButtonState.Pushed; } case CheckBoxStates.UncheckedDisabled: { return ButtonState.Inactive; } case CheckBoxStates.CheckedNormal: case CheckBoxStates.CheckedHot: { return ButtonState.Checked; } case CheckBoxStates.CheckedPressed: { return (ButtonState.Checked | ButtonState.Pushed); } case CheckBoxStates.CheckedDisabled: { return (ButtonState.Checked | ButtonState.Inactive); } case CheckBoxStates.MixedNormal: case CheckBoxStates.MixedHot: { return ButtonState.Checked; } case CheckBoxStates.MixedPressed: { return (ButtonState.Checked | ButtonState.Pushed); } case CheckBoxStates.MixedDisabled: { return (ButtonState.Checked | ButtonState.Inactive); } } return ButtonState.Normal; }
/// <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)); } } }