internal static ButtonState ConvertToButtonState(CheckBoxState state) { switch (state) { case CheckBoxState.UncheckedPressed: return ButtonState.Pushed; case CheckBoxState.UncheckedDisabled: return ButtonState.Inactive; case CheckBoxState.CheckedNormal: case CheckBoxState.CheckedHot: return ButtonState.Checked; case CheckBoxState.CheckedPressed: return (ButtonState.Checked | ButtonState.Pushed); case CheckBoxState.CheckedDisabled: return (ButtonState.Checked | ButtonState.Inactive); case CheckBoxState.MixedNormal: case CheckBoxState.MixedHot: return ButtonState.Checked; case CheckBoxState.MixedPressed: return (ButtonState.Checked | ButtonState.Pushed); case CheckBoxState.MixedDisabled: return (ButtonState.Checked | ButtonState.Inactive); } return ButtonState.Normal; }
public static void DrawCheckBox (Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, CheckBoxState state) { Rectangle bounds = new Rectangle (glyphLocation, GetGlyphSize (g, state)); if (Application.RenderWithVisualStyles || always_use_visual_styles == true) { VisualStyleRenderer vsr = GetCheckBoxRenderer (state); vsr.DrawBackground (g, bounds); if (image != null) vsr.DrawImage (g, imageBounds, image); if (focused) ControlPaint.DrawFocusRectangle (g, textBounds); if (checkBoxText != String.Empty) if (state == CheckBoxState.CheckedDisabled || state == CheckBoxState.MixedDisabled || state == CheckBoxState.UncheckedDisabled) TextRenderer.DrawText (g, checkBoxText, font, textBounds, SystemColors.GrayText, flags); else TextRenderer.DrawText (g, checkBoxText, font, textBounds, SystemColors.ControlText, flags); } else { switch (state) { case CheckBoxState.CheckedDisabled: case CheckBoxState.MixedDisabled: case CheckBoxState.MixedPressed: ControlPaint.DrawCheckBox (g, bounds, ButtonState.Inactive | ButtonState.Checked); break; case CheckBoxState.CheckedHot: case CheckBoxState.CheckedNormal: ControlPaint.DrawCheckBox (g, bounds, ButtonState.Checked); break; case CheckBoxState.CheckedPressed: ControlPaint.DrawCheckBox (g, bounds, ButtonState.Pushed | ButtonState.Checked); break; case CheckBoxState.MixedHot: case CheckBoxState.MixedNormal: ControlPaint.DrawMixedCheckBox (g, bounds, ButtonState.Checked); break; case CheckBoxState.UncheckedDisabled: case CheckBoxState.UncheckedPressed: ControlPaint.DrawCheckBox (g, bounds, ButtonState.Inactive); break; case CheckBoxState.UncheckedHot: case CheckBoxState.UncheckedNormal: ControlPaint.DrawCheckBox (g, bounds, ButtonState.Normal); break; } if (image != null) g.DrawImage (image, imageBounds); if (focused) ControlPaint.DrawFocusRectangle (g, textBounds); if (checkBoxText != String.Empty) TextRenderer.DrawText (g, checkBoxText, font, textBounds, SystemColors.ControlText, flags); } }
/// <include file='doc\CheckBoxRenderer.uex' path='docs/doc[@for="CheckBoxRenderer.IsBackgroundPartiallyTransparent"]/*' /> /// <devdoc> /// <para> /// Returns true if the background corresponding to the given state is partially transparent, else false. /// </para> /// </devdoc> public static bool IsBackgroundPartiallyTransparent(CheckBoxState state) { if (RenderWithVisualStyles) { InitializeRenderer((int)state); return visualStyleRenderer.IsBackgroundPartiallyTransparent(); } else { return false; //for downlevel, this is false } }
private Image CreateCheckBoxGlyph(CheckBoxState state) { Bitmap image = new Bitmap(this.imlCheck.ImageSize.Width, this.imlCheck.ImageSize.Height); using (Graphics graphics = Graphics.FromImage(image)) { Size glyphSize = CheckBoxRenderer.GetGlyphSize(graphics, state); CheckBoxRenderer.DrawCheckBox(graphics, new Point((image.Width - glyphSize.Width) / 2, (image.Height - glyphSize.Height) / 2), state); } return image; }
public static void DrawCheckBox( Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, TextFormatFlags flags, bool focused, CheckBoxState state) { DrawCheckBox(g, glyphLocation, textBounds, checkBoxText, font, flags, focused, state, IntPtr.Zero); }
private static bool IsMixed(CheckBoxState state) { switch (state) { case CheckBoxState.MixedNormal: case CheckBoxState.MixedHot: case CheckBoxState.MixedPressed: case CheckBoxState.MixedDisabled: return(true); } return(false); }
private void ToggleCheckState(object item) { CheckBoxState oldCheckState = GetItemCheckState(item); if (oldCheckState != CheckBoxState.Hidden && oldCheckState != CheckBoxState.Grayed) { CheckBoxState newCheckState = (oldCheckState == CheckBoxState.Checked) ? CheckBoxState.Unchecked : CheckBoxState.Checked; SetItemCheckState(item, newCheckState); } }
/// <summary> /// Set tree node and his children checkbox state recursively /// </summary> /// <param name="treeNode">tree node</param> /// <param name="checkboxState">checkbox state</param> internal void SetTreeNodeAndChildrenStateRecursively(TreeNode treeNode, CheckBoxState checkboxState) { if ((treeNode != null)) { SetTreeNodeState(treeNode, checkboxState); foreach (TreeNode objChildTreeNode in treeNode.Nodes) { SetTreeNodeAndChildrenStateRecursively(objChildTreeNode, checkboxState); } } }
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) { // The checkBox cell is disabled, so paint the border, // background, and disabled checkBox for the cell. if (!RealEnable) { // Draw the cell background, if specified. if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } // Draw the cell borders, if specified. if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } // Calculate the area in which to draw the checkBox. CheckBoxState state = value != null && (bool)value ? CheckBoxState.CheckedDisabled : CheckBoxState.UncheckedDisabled; Size size = CheckBoxRenderer.GetGlyphSize(graphics, state); Point center = new Point(cellBounds.X, cellBounds.Y); center.X += (cellBounds.Width - size.Width) / 2; center.Y += (cellBounds.Height - size.Height) / 2; // Draw the disabled checkBox. CheckBoxRenderer.DrawCheckBox(graphics, center, state); } else { // The checkBox cell is enabled, so let the base class // handle the painting. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
void UpdateChildrenForRootCheck(TreeNavigator rootnode, CheckBoxState newCheck) { if (!rootnode.MoveToChild()) { return; } do { rootnode.SetValue(nodeCheck, newCheck); } while (rootnode.MoveNext()); }
/// <summary> /// Set treenode checkbox state /// </summary> /// <param name="treeNode">treenode</param> /// <param name="state">checkbox state</param> protected void SetNodeState(TreeNode treeNode, CheckBoxState state) { if (!_NodeStateDict.ContainsKey(treeNode)) { _NodeStateDict.Add(treeNode, state); } else { _NodeStateDict[treeNode] = state; } OnCheckBoxStateChanged(new CheckBoxStateChangedEventArgs(state, treeNode)); }
private void buttonMoveUp_Click(object sender, EventArgs e) { IResource temp = _listRules.SelectedResource; int currIndex = _listRules.SelectedIndex; CheckBoxState state = _listRules.GetCheckState(temp); _listRules.Nodes.RemoveResource(temp); _listRules.Nodes.AddResourceAt(temp, currIndex - 1); _listRules.SetCheckState(temp, state); _listRules.SelectSingleItem(temp); CheckMoveButtons(); }
/// <summary> /// Implement the display of the value's representation.</summary> /// <param name="g">The Graphics object</param> /// <param name="area">Rectangle delimiting area to paint</param> public override void PaintValue(Graphics g, Rectangle area) { area.X += Theme.Padding.Left; area.Width -= Theme.Padding.Left + Theme.Padding.Right; const int checkBoxWidth = 12; if (area.Width >= checkBoxWidth) { // area.X += (area.Width - checkBoxWidth)/2; CheckBoxState state = Value ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(g, area.Location, state); } }
private static Image CreateCheckBoxGlyph(CheckBoxState state) { var result = new Bitmap(16, 16); using (Graphics g = Graphics.FromImage(result)) { Size glyphSize = CheckBoxRenderer.GetGlyphSize(g, state); CheckBoxRenderer.DrawCheckBox(g, new Point((result.Width - glyphSize.Width) / 2, (result.Height - glyphSize.Height) / 2), state); } return(result); }
///<summary> /// RenderCheckbox ///</summary> ///<param name="g"></param> ///<param name="bounds"></param> ///<param name="cstate"></param> ///<param name="bstate"></param> static public void RenderCheckbox( Graphics g, Rectangle bounds, CheckBoxState cstate, ButtonState bstate) { if (Application.RenderWithVisualStyles == true && CheckBoxRenderer.GetGlyphSize(g, cstate) == bounds.Size) { CheckBoxRenderer.DrawCheckBox(g, bounds.Location, cstate); } else { ControlPaint.DrawCheckBox(g, bounds, bstate); } }
public static bool IsValid(this CheckBoxState state) { switch (state) { case CheckBoxState.Off: case CheckBoxState.On: case CheckBoxState.Mixed: return(true); default: return(false); } }
private void SetTreeNodeAndChildrenStateRecursively(TriStateTreeNode node, CheckBoxState state) { if (node == null) { return; } this.SetTreeNodeState(node, state); foreach (TriStateTreeNode childNode in node.Nodes) { this.SetTreeNodeAndChildrenStateRecursively(childNode, state); } }
private static bool IsDisabled(CheckBoxState state) { switch (state) { case CheckBoxState.CheckedDisabled: case CheckBoxState.UncheckedDisabled: case CheckBoxState.MixedDisabled: return(true); default: return(false); } }
/// <include file='doc\CheckBoxRenderer.uex' path='docs/doc[@for="CheckBoxRenderer.IsBackgroundPartiallyTransparent"]/*' /> /// <devdoc> /// <para> /// Returns true if the background corresponding to the given state is partially transparent, else false. /// </para> /// </devdoc> public static bool IsBackgroundPartiallyTransparent(CheckBoxState state) { if (RenderWithVisualStyles) { InitializeRenderer((int)state); return(visualStyleRenderer.IsBackgroundPartiallyTransparent()); } else { return(false); //for downlevel, this is false } }
internal static void DrawCheckBoxWithVisualStyles( IDeviceContext deviceContext, Point glyphLocation, CheckBoxState state, IntPtr hwnd = default) { InitializeRenderer((int)state); using var hdc = new DeviceContextHdcScope(deviceContext); Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(hdc, state, hwnd)); t_visualStyleRenderer.DrawBackground(hdc, glyphBounds, hwnd); }
/// <summary> /// Add TreeNode /// </summary> /// <param name="nodes">node collection</param> /// <param name="treeNode">TreeNode</param> /// <param name="iImageIndex">image index</param> /// <param name="checkboxState">check box state</param> /// <returns></returns> protected TreeNode AddTreeNode(TreeNodeCollection nodes, TreeNode treeNode, CheckBoxState checkboxState) { if (!nodes.Contains(treeNode)) { nodes.Add(treeNode); } this.SetTreeNodeState(treeNode, checkboxState); SetTreeNodeAndChildrenStateRecursively(treeNode, checkboxState); SetParentTreeNodeStateRecursively(treeNode.Parent); return(treeNode); }
/// <summary> /// Converts the specified CheckBoxState value to a ButtonState value /// </summary> /// <param name="state">The CheckBoxState value to be converted</param> /// <returns>A ButtonState value that represents the specified CheckBoxState /// value</returns> private static ButtonState ConvertCheckBoxStateToButtonState(CheckBoxState state) { switch (state) { case CheckBoxState.UncheckedPressed: { return(ButtonState.Pushed); } case CheckBoxState.UncheckedDisabled: { return(ButtonState.Inactive); } case CheckBoxState.CheckedNormal: case CheckBoxState.CheckedHot: { return(ButtonState.Checked); } case CheckBoxState.CheckedPressed: { return(ButtonState.Checked | ButtonState.Pushed); } case CheckBoxState.CheckedDisabled: { return(ButtonState.Checked | ButtonState.Inactive); } case CheckBoxState.MixedNormal: case CheckBoxState.MixedHot: { return(ButtonState.Checked); } case CheckBoxState.MixedPressed: { return(ButtonState.Checked | ButtonState.Pushed); } case CheckBoxState.MixedDisabled: { return(ButtonState.Checked | ButtonState.Inactive); } } return(ButtonState.Normal); }
/// <summary> /// Draws the checkbox when the TreeListView is using the CheckedList style</summary> /// <param name="node">Node whose checkbox is drawn</param> /// <param name="gfx">GDI+ graphics object</param> /// <param name="bounds">Rectangle bounding area to draw</param> public virtual void DrawCheckBox(Node node, Graphics gfx, Rectangle bounds) { bool enabled = Owner.Control.Enabled; CheckBoxState state = node.CheckState == CheckState.Checked ? (enabled ? CheckBoxState.CheckedNormal : CheckBoxState.CheckedDisabled) : (enabled ? CheckBoxState.UncheckedNormal : CheckBoxState.UncheckedDisabled); CheckBoxRenderer.DrawCheckBox(gfx, bounds.Location, state); }
private void ArgumentsList_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawBackground(); if (e.ItemIndex < ArgumentsList.Items.Count - 1) { CheckBoxState State = e.Item.Checked? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; Size CheckSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, State); CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + (e.Bounds.Height - CheckSize.Height) / 2), State); DrawItemLabel(e.Graphics, SystemColors.WindowText, e.Item); } else { DrawItemLabel(e.Graphics, SystemColors.GrayText, e.Item); } }
/// <summary> /// The paint. /// </summary> /// <param name="graphics"> /// The graphics. /// </param> /// <param name="clipBounds"> /// The clip bounds. /// </param> /// <param name="cellBounds"> /// The cell bounds. /// </param> /// <param name="rowIndex"> /// The row index. /// </param> /// <param name="dataGridViewElementState"> /// The data grid view element state. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="formattedValue"> /// The formatted value. /// </param> /// <param name="errorText"> /// The error text. /// </param> /// <param name="cellStyle"> /// The cell style. /// </param> /// <param name="advancedBorderStyle"> /// The advanced border style. /// </param> /// <param name="paintParts"> /// The paint parts. /// </param> 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, string.Empty, string.Empty, errorText, cellStyle, advancedBorderStyle, paintParts); Point p = new Point(); Size s = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal); p.X = cellBounds.Location.X + (cellBounds.Width / 2) - (s.Width / 2); p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2); this.cellLocation = cellBounds.Location; this.checkBoxLocation = p; this.checkBoxSize = s; if (this.isChecked) { this.cbState = CheckBoxState.CheckedNormal; } else { this.cbState = CheckBoxState.UncheckedNormal; } CheckBoxRenderer.DrawCheckBox(graphics, this.checkBoxLocation, this.cbState); }
protected override void OnDrawItem(DrawItemEventArgs e) { bool changed = (Defaults != null) && (Defaults.Length == Items.Count) && (e.Index != -1) && (e.Index < Defaults.Length) && (e.Index < Items.Count) && GetItemChecked(e.Index) ^ Defaults[e.Index]; Color backColor = Color.Empty; Color foreColor = Color.Empty; if (!Enabled && changed) { backColor = Color.LightBlue; foreColor = SystemColors.GrayText; } else if (Enabled && changed) { backColor = Settings.ModifiedColor.BackgroundColor; foreColor = Settings.ModifiedColor.ForegroundColor; } else if (!Enabled && !changed) { backColor = BackColor; foreColor = SystemColors.GrayText; } else { backColor = BackColor; foreColor = ForeColor; } using (Brush backColorBrush = new SolidBrush(backColor)) using (Brush foreColorBrush = new SolidBrush(foreColor)) { e.Graphics.FillRectangle(backColorBrush, e.Bounds); if ((e.Index < Items.Count) && (e.Index != -1)) { CheckBoxState state = this.GetItemChecked(e.Index) ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; Size checkBoxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state); Point loc = new Point(1, (e.Bounds.Height - (checkBoxSize.Height + 1)) / 2 + 1); CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(loc.X + e.Bounds.X, loc.Y + e.Bounds.Y), state); e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, foreColorBrush, new PointF(loc.X + checkBoxSize.Width + 1 + e.Bounds.X, loc.Y + e.Bounds.Y)); } } }
private void UpdateCheckBoxImage(CheckBoxState state) { // Running this in switch statement if further implementation will be needed for each case. switch (state) { case CheckBoxState.DefaultState: pbCheckBox.Image = _boxImages[CheckBoxState.DefaultState]; break; case CheckBoxState.DefaultStateHover: pbCheckBox.Image = _boxImages[CheckBoxState.DefaultStateHover]; break; case CheckBoxState.Disabled: pbCheckBox.Image = _boxImages[CheckBoxState.Disabled]; break; case CheckBoxState.Checked: pbCheckBox.Image = _boxImages[CheckBoxState.Checked]; break; case CheckBoxState.CheckedHover: pbCheckBox.Image = _boxImages[CheckBoxState.CheckedHover]; break; case CheckBoxState.ClickCheck: pbCheckBox.Image = _boxImages[CheckBoxState.ClickCheck]; break; case CheckBoxState.ClickUncheck: pbCheckBox.Image = _boxImages[CheckBoxState.ClickUncheck]; break; case CheckBoxState.WrongAnswer: pbCheckBox.Image = _boxImages[CheckBoxState.WrongAnswer]; break; case CheckBoxState.WrongSelected: pbCheckBox.Image = _boxImages[CheckBoxState.WrongSelected]; break; default: pbCheckBox.Image = _boxImages[CheckBoxState.DefaultState]; MessageBox.Show("[UpdateCheckBoxImage] - Unmatched Switch case, setting to default state."); break; } }
private Rectangle DrawCheckBox(Graphics g, Rectangle r, CheckState checkState, bool isDisabled, bool isHot, bool isPressed) { CheckBoxState checkBoxState = GetCheckBoxState(checkState, isDisabled, isHot, isPressed); Rectangle checkBoxBounds = CalculateCheckBoxBounds(g, r); CheckBoxRenderer.DrawCheckBox(g, checkBoxBounds.Location, checkBoxState); // Move the left edge without changing the right edge int newX = checkBoxBounds.Right + 3; r.Width -= (newX - r.X); r.X = newX; return(r); }
void UpdateCheckboxDependencies(TreePosition updatedRow) { var node = store.GetNavigatorAt(updatedRow); bool isRoot = node.GetValue(nodeIconVisible); CheckBoxState newCheck = node.GetValue(nodeCheck); if (isRoot) { UpdateChildrenForRootCheck(node, newCheck); return; } UpdateNextChildrenOffset(node, newCheck); UpdateRootFromChild(node, newCheck); }
public void SetItemCheckState(object item, CheckBoxState newCheckState) { CheckBoxEventArgs args = new CheckBoxEventArgs(item, GetItemCheckState(item), newCheckState); if (BeforeCheck != null) { BeforeCheck(this, args); } _checkStates [item] = args.NewState; if (args.OldState != args.NewState) { OnAfterCheck(args); OwnerControl.InvalidateItem(item); } }
public void Paint(System.Drawing.Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle) { CheckBoxState checkBoxState = CheckBoxState.UncheckedDisabled; if (value is bool && Convert.ToBoolean(value)) { checkBoxState = CheckBoxState.CheckedDisabled; } Size checkBoxSize = CheckBoxRenderer.GetGlyphSize(graphics, checkBoxState); Point drawInPoint = new Point(cellBounds.X + cellBounds.Width / 2 - checkBoxSize.Width / 2, cellBounds.Y + cellBounds.Height / 2 - checkBoxSize.Height / 2); CheckBoxRenderer.DrawCheckBox(graphics, drawInPoint, checkBoxState); }
/// <summary> /// Constructs a dialog based on the Yes/No template using the provided information /// </summary> /// <param name="question">The main description for the dialog</param> /// <param name="yesLabel">Positive response label, null to disable</param> /// <param name="noLabel">Negative response label, null to disable</param> /// <param name="state">State of the skip dialog checkbox. Possible status: Hidden/NotChecked/Checked</param> public YesNoDialog(String question, String yesLabel, String noLabel, CheckBoxState state = CheckBoxState.Hidden) { InitializeComponent(); questionLabel.Text = question; // Only show buttons if a label was passed if (yesLabel != null) { yesButton.Text = yesLabel; } else { yesButton.Visible = false; } if (noLabel != null) { noButton.Text = noLabel; } else { noButton.Visible = false; } // Close dialog when a response has been chosen yesButton.Click += (sender, args) => Close(); noButton.Click += (sender, args) => Close(); // Load the checkbox state switch (state) { case CheckBoxState.Hidden: askAgainCheckBox.Visible = false; break; case CheckBoxState.Checked: askAgainCheckBox.Visible = true; askAgainCheckBox.Checked = true; break; case CheckBoxState.NotChecked: askAgainCheckBox.Checked = false; askAgainCheckBox.Visible = true; break; } }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { Rectangle r = e.Bounds; if (r.Width > this.ClientSize.Width) { r.Width = this.ClientSize.Width; } Graphics g = e.Graphics; r.X += 1; //3 r.Width -= 2; int offset = 0; bool isSelected = e.Item == m_hoverItem; Brush backBrush = isSelected ? SystemBrushes.Highlight : new SolidBrush(this.BackColor); g.FillRectangle(backBrush, r); if (this.CheckBoxes) { CheckBoxState boxState = e.Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(g, new Point(r.X + 3, r.Y + (r.Height / 2) - 6), boxState); offset = CheckBoxRenderer.GetGlyphSize(g, boxState).Width + 6; r.X += offset; r.Width -= offset; } int imgFlags = ILD_TRANSPARENT; if (isSelected) { imgFlags |= ILD_BLEND25; } int imgIndex = this.SmallImageList.Images.IndexOfKey(e.Item.ImageKey); bool result = ImageList_Draw(this.SmallImageList.Handle, imgIndex, g.GetHdc(), r.X, r.Y, imgFlags); g.ReleaseHdc(); offset = this.SmallImageList.ImageSize.Width; r.X += offset; r.Width -= offset; string txt = e.Item.SubItems[0].Text; Color backColor = isSelected ? SystemColors.Highlight : Color.Transparent; Color foreColor = isSelected ? SystemColors.HighlightText : this.ForeColor; TextFormatFlags textFlags = TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.SingleLine; TextRenderer.DrawText(g, txt, this.Font, r, foreColor, backColor, textFlags); }
public static NSCellStateValue ToMacState(this CheckBoxState state) { switch (state) { case CheckBoxState.Mixed: return(NSCellStateValue.Mixed); case CheckBoxState.On: return(NSCellStateValue.On); case CheckBoxState.Off: return(NSCellStateValue.Off); default: throw new ArgumentOutOfRangeException(); } }
void UpdateNextChildrenOffset(TreeNavigator node, CheckBoxState newCheck) { var iter = node.Clone(); var change = node.GetValue(nodeEditor); var diff = change.NewText.Length - change.Span.Length; if (newCheck == CheckBoxState.Off) { diff = -diff; } while (iter.MoveNext()) { var currentOffset = iter.GetValue(nodeOffset); iter.SetValue(nodeOffset, currentOffset + diff); } }
/// <summary> /// Constructs a dialog based on the Yes/No template using the provided information /// </summary> /// <param name="question">The main description for the dialog</param> /// <param name="yesLabel">Positive response label, null to disable</param> /// <param name="noLabel">Negative response label, null to disable</param> /// <param name="state">State of the skip dialog checkbox. Possible status: Hidden/NotChecked/Checked</param> public YesNoDialog(String question, String yesLabel, String noLabel, CheckBoxState state = CheckBoxState.Hidden) { InitializeComponent(); questionLabel.Text = question; // Only show buttons if a label was passed if (yesLabel != null) yesButton.Text = yesLabel; else yesButton.Visible = false; if (noLabel != null) noButton.Text = noLabel; else noButton.Visible = false; // Close dialog when a response has been chosen yesButton.Click += (sender, args) => Close(); noButton.Click += (sender, args) => Close(); // Load the checkbox state switch (state) { case CheckBoxState.Hidden: askAgainCheckBox.Visible = false; break; case CheckBoxState.Checked: askAgainCheckBox.Visible = true; askAgainCheckBox.Checked = true; break; case CheckBoxState.NotChecked: askAgainCheckBox.Checked = false; askAgainCheckBox.Visible = true; break; } }
/// <summary> /// Handles when the mouse has left the area of the <see cref="Control"/>. /// This is called immediately before <see cref="Control.OnMouseLeave"/>. /// Override this method instead of using an event hook on <see cref="Control.MouseLeave"/> when possible. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseLeave(MouseMoveEventArgs e) { base.OnMouseLeave(e); _state = CheckBoxState.None; }
public static void DrawCheckBox (Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, TextFormatFlags flags, bool focused, CheckBoxState state) { DrawCheckBox (g, glyphLocation, textBounds, checkBoxText, font, flags, null, Rectangle.Empty, focused, state); }
public static void DrawCheckBox (Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, Image image, Rectangle imageBounds, bool focused, CheckBoxState state) { DrawCheckBox (g, glyphLocation, textBounds, checkBoxText, font, TextFormatFlags.HorizontalCenter, image, imageBounds, focused, state); }
private static VisualStyleRenderer GetCheckBoxRenderer (CheckBoxState state) { switch (state) { case CheckBoxState.CheckedDisabled: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.CheckedDisabled); case CheckBoxState.CheckedHot: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.CheckedHot); case CheckBoxState.CheckedNormal: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.CheckedNormal); case CheckBoxState.CheckedPressed: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.CheckedPressed); case CheckBoxState.MixedDisabled: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.MixedDisabled); case CheckBoxState.MixedHot: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.MixedHot); case CheckBoxState.MixedNormal: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.MixedNormal); case CheckBoxState.MixedPressed: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.MixedPressed); case CheckBoxState.UncheckedDisabled: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.UncheckedDisabled); case CheckBoxState.UncheckedHot: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.UncheckedHot); case CheckBoxState.UncheckedNormal: default: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.UncheckedNormal); case CheckBoxState.UncheckedPressed: return new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.UncheckedPressed); } }
public static void DrawCheckBox (Graphics g, Point glyphLocation, CheckBoxState state) { DrawCheckBox (g, glyphLocation, Rectangle.Empty, String.Empty, null, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, false, state); }
public static bool IsBackgroundPartiallyTransparent (CheckBoxState state) { if (!VisualStyleRenderer.IsSupported) return false; VisualStyleRenderer vsr = GetCheckBoxRenderer (state); return vsr.IsBackgroundPartiallyTransparent (); }
public static Size GetGlyphSize (Graphics g, CheckBoxState state) { if (!VisualStyleRenderer.IsSupported) return new Size (13, 13); VisualStyleRenderer vsr = GetCheckBoxRenderer (state); return vsr.GetPartSize (g, ThemeSizeType.Draw); }
private Bitmap GenerateCheckBoxBitmap(CheckBoxState state) { var uncheckedImage = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(uncheckedImage)) { Size glyphSize = CheckBoxRenderer.GetGlyphSize(g, state); CheckBoxRenderer.DrawCheckBox(g, new Point((16 / 2) - (glyphSize.Width / 2), (16 / 2) - (glyphSize.Height / 2)), state); } return uncheckedImage; }
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; }
public void DrawCheckBox(Graphics g, Point loc, CheckBoxState state) { InitCheckBox(state); g.DrawImageUnscaled(checkBoxImages[state], loc); }
protected internal override void OnMouseUp( Point _hitPoint, int _iButton ) { if( mbIsHovered ) { CheckBoxState newState = ( CheckState == CheckBoxState.Checked ) ? CheckBoxState.Unchecked : CheckBoxState.Checked; if( ChangeHandler != null ) ChangeHandler( this, newState ); CheckState = newState; } }
/// <summary> /// Handles when the <see cref="Control"/> has lost focus. /// This is called immediately before <see cref="Control.OnLostFocus"/>. /// Override this method instead of using an event hook on <see cref="Control.LostFocus"/> when possible. /// </summary> protected override void OnLostFocus() { base.OnLostFocus(); _state = CheckBoxState.None; }
/// <summary> /// Handles when a mouse button has been raised on the <see cref="Control"/>. /// This is called immediately before <see cref="Control.OnMouseUp"/>. /// Override this method instead of using an event hook on <see cref="Control.MouseUp"/> when possible. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); _state = CheckBoxState.Over; }
private static Bitmap GetCheckboxBitmap(CheckBoxState state) { /* http://stackoverflow.com/questions/5626031/tri-state-checkboxes-in-winforms-treeview */ var bmp = new Bitmap(16, 16); using (var g = System.Drawing.Graphics.FromImage(bmp)) { CheckBoxRenderer.DrawCheckBox(g, new Point(0, 1), state); } return bmp; }
/// <summary> /// Converts the specified CheckBoxState value to a ButtonState value /// </summary> /// <param name="state">The CheckBoxState value to be converted</param> /// <returns>A ButtonState value that represents the specified CheckBoxState /// value</returns> private static ButtonState ConvertCheckBoxStateToButtonState(CheckBoxState state) { switch (state) { case CheckBoxState.UncheckedPressed: { return ButtonState.Pushed; } case CheckBoxState.UncheckedDisabled: { return ButtonState.Inactive; } case CheckBoxState.CheckedNormal: case CheckBoxState.CheckedHot: { return ButtonState.Checked; } case CheckBoxState.CheckedPressed: { return (ButtonState.Checked | ButtonState.Pushed); } case CheckBoxState.CheckedDisabled: { return (ButtonState.Checked | ButtonState.Inactive); } case CheckBoxState.MixedNormal: case CheckBoxState.MixedHot: { return ButtonState.Checked; } case CheckBoxState.MixedPressed: { return (ButtonState.Checked | ButtonState.Pushed); } case CheckBoxState.MixedDisabled: { return (ButtonState.Checked | ButtonState.Inactive); } } return ButtonState.Normal; }
/// <summary> /// Returns whether the specified CheckBoxState value is in an /// indeterminate state /// </summary> /// <param name="state">The CheckBoxState value to be checked</param> /// <returns>true if the specified CheckBoxState value is in an /// indeterminate state, false otherwise</returns> private static bool IsMixed(CheckBoxState state) { switch (state) { case CheckBoxState.MixedNormal: case CheckBoxState.MixedHot: case CheckBoxState.MixedPressed: case CheckBoxState.MixedDisabled: { return true; } } return false; }
private void InitCheckBox(CheckBoxState checkState) { if (checkBoxImages != null && checkBoxImages.ContainsKey(checkState)) return; if (checkBoxImages == null) checkBoxImages = new Dictionary<CheckBoxState,Bitmap>(); Bitmap image = new Bitmap(CheckBoxSize.Width, CheckBoxSize.Height); using (Graphics checkBoxGraphics = Graphics.FromImage(image)) { if (checkState == CheckBoxState.PlusDisabled || checkState == CheckBoxState.PlusHot || checkState == CheckBoxState.PlusNormal || checkState == CheckBoxState.PlusPressed || checkState == CheckBoxState.MinusDisabled || checkState == CheckBoxState.MinusHot || checkState == CheckBoxState.MinusNormal || checkState == CheckBoxState.MinusPressed) { Color plusSignColor; Pen expandLineShadowPen; Pen expandLinePen; if (checkState == CheckBoxState.PlusNormal || checkState == CheckBoxState.MinusNormal) { plusSignColor = Color.FromArgb(24, 32, 82); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(64, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); } else if (checkState == CheckBoxState.PlusHot || checkState == CheckBoxState.MinusHot) { plusSignColor = Color.FromArgb(32, 48, 123); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(64, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot); } else if (checkState == CheckBoxState.PlusPressed || checkState == CheckBoxState.MinusPressed) { plusSignColor = Color.FromArgb(48, 64, 164); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(96, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedPressed); } else //if (checkState == CheckBoxState.PlusDisabled) { plusSignColor = Color.FromArgb(24, 28, 41); expandLinePen = new Pen(Color.FromArgb(128, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(32, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled); } // Plus Shadow checkBoxGraphics.DrawLine(expandLineShadowPen, 3, image.Height / 2 + 1, image.Width - 4, image.Height / 2 + 1); checkBoxGraphics.DrawLine(expandLineShadowPen, 3, image.Height / 2 - 1, image.Width - 4, image.Height / 2 - 1); if (checkState == CheckBoxState.PlusDisabled || checkState == CheckBoxState.PlusHot || checkState == CheckBoxState.PlusNormal || checkState == CheckBoxState.PlusPressed) { checkBoxGraphics.DrawLine(expandLineShadowPen, image.Width / 2 + 1, 3, image.Width / 2 + 1, image.Height - 4); checkBoxGraphics.DrawLine(expandLineShadowPen, image.Width / 2 - 1, 3, image.Width / 2 - 1, image.Height - 4); } // Plus checkBoxGraphics.DrawLine(expandLinePen, 3, image.Height / 2, image.Width - 4, image.Height / 2); if (checkState == CheckBoxState.PlusDisabled || checkState == CheckBoxState.PlusHot || checkState == CheckBoxState.PlusNormal || checkState == CheckBoxState.PlusPressed) { checkBoxGraphics.DrawLine(expandLinePen, image.Width / 2, 3, image.Width / 2, image.Height - 4); } } else { CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, (System.Windows.Forms.VisualStyles.CheckBoxState)checkState); } } checkBoxImages[checkState] = image; }
//绘制列头checkbox 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) - 1;//列头checkbox的X坐标 p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2);//列头checkbox的Y坐标 _cellLocation = cellBounds.Location; checkBoxLocation = p; checkBoxSize = s; if (_checked) _cbState = CheckBoxState.CheckedNormal; else _cbState = CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(graphics, checkBoxLocation, _cbState); }
/// <summary> /// Handles when a mouse button has been pressed down on this <see cref="Control"/>. /// This is called immediately before <see cref="Control.OnMouseDown"/>. /// Override this method instead of using an event hook on <see cref="Control.MouseDown"/> when possible. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseDown(MouseButtonEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButton.Left) { Value = !_value; _state = CheckBoxState.Pressed; } }
//build the checked, unchecked and indeterminate images private static Image GetStateImage(CheckBoxState state, Size imageSize) { Bitmap bmp = new Bitmap(16, 16); using (Graphics g = Graphics.FromImage(bmp)) { Point pt = new Point((16 - imageSize.Width) / 2, (16 - imageSize.Height) / 2); CheckBoxRenderer.DrawCheckBox(g, pt, state); } return bmp; }
/// <summary> /// Handles when the mouse has moved over the <see cref="Control"/>. /// This is called immediately before <see cref="Control.MouseMoved"/>. /// Override this method instead of using an event hook on <see cref="Control.MouseMoved"/> when possible. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseMoved(MouseMoveEventArgs e) { base.OnMouseMoved(e); _state = CheckBoxState.Over; }
/// <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 CheckBoxState value that specifies the /// state to draw the check box in</param> public static void DrawCheck(Graphics g, Rectangle checkRect, CheckBoxState state) { ThemeManager.DrawCheck(g, checkRect, checkRect, state); }
private void AddCheckStateBitmap(ImageList il, string key, CheckBoxState boxState) { Bitmap b = new Bitmap(il.ImageSize.Width, il.ImageSize.Height); Graphics g = Graphics.FromImage(b); g.Clear(il.TransparentColor); Point location = new Point(b.Width / 2 - 5, b.Height / 2 - 6); CheckBoxRenderer.DrawCheckBox(g, location, boxState); il.Images.Add(key, b); }
/// <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)); } } }