static void DrawRadioButton (Graphics g, Rectangle bounds, RadioButtonState state) { RadioButtonRenderer.DrawRadioButton ( g, bounds.Location, state ); }
/// <include file='doc\RadioButtonRenderer.uex' path='docs/doc[@for="RadioButtonRenderer.IsBackgroundPartiallyTransparent"]/*' /> /// <devdoc> /// <para> /// Returns true if the background corresponding to the given state is partially transparent, else false. /// </para> /// </devdoc> public static bool IsBackgroundPartiallyTransparent(RadioButtonState state) { if (RenderWithVisualStyles) { InitializeRenderer((int)state); return visualStyleRenderer.IsBackgroundPartiallyTransparent(); } else { return false; //for downlevel, this is false } }
public static void DrawRadioButton (Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, RadioButtonState state) { Rectangle bounds = new Rectangle (glyphLocation, GetGlyphSize (g, state)); if (Application.RenderWithVisualStyles || always_use_visual_styles == true) { VisualStyleRenderer vsr = GetRadioButtonRenderer (state); vsr.DrawBackground (g, bounds); if (image != null) vsr.DrawImage (g, imageBounds, image); if (focused) ControlPaint.DrawFocusRectangle (g, textBounds); if (radioButtonText != String.Empty) if (state == RadioButtonState.CheckedDisabled || state == RadioButtonState.UncheckedDisabled) TextRenderer.DrawText (g, radioButtonText, font, textBounds, SystemColors.GrayText, flags); else TextRenderer.DrawText (g, radioButtonText, font, textBounds, SystemColors.ControlText, flags); } else { switch (state) { case RadioButtonState.CheckedDisabled: ControlPaint.DrawRadioButton (g, bounds, ButtonState.Inactive | ButtonState.Checked); break; case RadioButtonState.CheckedHot: case RadioButtonState.CheckedNormal: ControlPaint.DrawRadioButton (g, bounds, ButtonState.Checked); break; case RadioButtonState.CheckedPressed: ControlPaint.DrawRadioButton (g, bounds, ButtonState.Pushed | ButtonState.Checked); break; case RadioButtonState.UncheckedDisabled: case RadioButtonState.UncheckedPressed: ControlPaint.DrawRadioButton (g, bounds, ButtonState.Inactive); break; case RadioButtonState.UncheckedHot: case RadioButtonState.UncheckedNormal: ControlPaint.DrawRadioButton (g, bounds, ButtonState.Normal); break; } if (image != null) g.DrawImage (image, imageBounds); if (focused) ControlPaint.DrawFocusRectangle (g, textBounds); if (radioButtonText != String.Empty) TextRenderer.DrawText (g, radioButtonText, font, textBounds, SystemColors.ControlText, flags); } }
public static void DrawRadioButton(Graphics g, Point glyphLocation, RadioButtonState state) { Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state)); if (RenderWithVisualStyles) { InitializeRenderer((int) state); visualStyleRenderer.DrawBackground(g, bounds); } else { ControlPaint.DrawRadioButton(g, bounds, ConvertToButtonState(state)); } }
internal static ButtonState ConvertToButtonState(RadioButtonState state) { switch (state) { case RadioButtonState.UncheckedPressed: return ButtonState.Pushed; case RadioButtonState.UncheckedDisabled: return ButtonState.Inactive; case RadioButtonState.CheckedNormal: case RadioButtonState.CheckedHot: return ButtonState.Checked; case RadioButtonState.CheckedPressed: return (ButtonState.Checked | ButtonState.Pushed); case RadioButtonState.CheckedDisabled: return (ButtonState.Checked | ButtonState.Inactive); } return ButtonState.Normal; }
public static void DrawRadioButton (Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, bool focused, RadioButtonState state) { DrawRadioButton (g, glyphLocation, textBounds, radioButtonText, font, flags, null, Rectangle.Empty, focused, state); }
public static void DrawRadioButton (Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, Image image, Rectangle imageBounds, bool focused, RadioButtonState state) { DrawRadioButton (g, glyphLocation, textBounds, radioButtonText, font, TextFormatFlags.HorizontalCenter, image, imageBounds, focused, state); }
private static VisualStyleRenderer GetRadioButtonRenderer (RadioButtonState state) { switch (state) { case RadioButtonState.CheckedDisabled: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.CheckedDisabled); case RadioButtonState.CheckedHot: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.CheckedHot); case RadioButtonState.CheckedNormal: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.CheckedNormal); case RadioButtonState.CheckedPressed: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.CheckedPressed); case RadioButtonState.UncheckedDisabled: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.UncheckedDisabled); case RadioButtonState.UncheckedHot: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.UncheckedHot); case RadioButtonState.UncheckedNormal: default: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.UncheckedNormal); case RadioButtonState.UncheckedPressed: return new VisualStyleRenderer (VisualStyleElement.Button.RadioButton.UncheckedPressed); } }
public static void DrawRadioButton (Graphics g, Point glyphLocation, RadioButtonState state) { DrawRadioButton (g, glyphLocation, Rectangle.Empty, String.Empty, null, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, false, state); }
// Let the item paint itself, and then paint the RadioButton // where the check mark is normally displayed. protected override void OnPaint(PaintEventArgs e) { if (Image != null) { // If the client sets the Image property, the selection behavior // remains unchanged, but the RadioButton is not displayed and the // selection is indicated only by the selection rectangle. base.OnPaint(e); return; } else { // If the Image property is not set, call the base OnPaint method // with the CheckState property temporarily cleared to prevent // the check mark from being painted. CheckState currentState = this.CheckState; this.CheckState = CheckState.Unchecked; base.OnPaint(e); this.CheckState = currentState; } // Determine the correct state of the RadioButton. RadioButtonState buttonState = RadioButtonState.UncheckedNormal; if (Enabled) { if (mouseDownState) { if (Checked) { buttonState = RadioButtonState.CheckedPressed; } else { buttonState = RadioButtonState.UncheckedPressed; } } else if (mouseHoverState) { if (Checked) { buttonState = RadioButtonState.CheckedHot; } else { buttonState = RadioButtonState.UncheckedHot; } } else { if (Checked) { buttonState = RadioButtonState.CheckedNormal; } } } else { if (Checked) { buttonState = RadioButtonState.CheckedDisabled; } else { buttonState = RadioButtonState.UncheckedDisabled; } } // Calculate the position at which to display the RadioButton. Int32 offset = (ContentRectangle.Height - RadioButtonRenderer.GetGlyphSize( e.Graphics, buttonState).Height) / 2; Point imageLocation = new Point( ContentRectangle.Location.X + 4, ContentRectangle.Location.Y + offset); // Paint the RadioButton. RadioButtonRenderer.DrawRadioButton( e.Graphics, imageLocation, buttonState); }
public static Size GetGlyphSize (Graphics g, RadioButtonState state) { if (!VisualStyleRenderer.IsSupported) return new Size (13, 13); VisualStyleRenderer vsr = GetRadioButtonRenderer(state); return vsr.GetPartSize (g, ThemeSizeType.Draw); }
/// <summary> /// Draws a RadioButton 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 RadioButton</param> /// <param name="state">A RadioButtonState value that specifies the /// state to draw the RadioButton in</param> public static void DrawRadioButton(Graphics g, Rectangle checkRect, RadioButtonState state) { ThemeManager.DrawRadioButton(g, checkRect, checkRect, state); }
/// <summary> /// Draws a RadioButton 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 RadioButton</param> /// <param name="clipRect">The Rectangle that represents the clipping area</param> /// <param name="state">A RadioButtonState value that specifies the /// state to draw the RadioButton in</param> public static void DrawRadioButton(Graphics g, Rectangle checkRect, Rectangle clipRect, RadioButtonState state) { if (g == null || checkRect.Width <= 0 || checkRect.Height <= 0) { return; } if (ThemeManager.VisualStylesEnabled) { //ThemeManager.DrawThemeBackground(g, ThemeClasses.Button, (int) ButtonParts.RadioButton, (int) state, checkRect, clipRect); VisualStyleRenderer renderer; switch (state) { case RadioButtonState.CheckedDisabled: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.CheckedDisabled); break; case RadioButtonState.CheckedHot: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.CheckedHot); break; case RadioButtonState.CheckedNormal: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.CheckedNormal); break; case RadioButtonState.CheckedPressed: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.CheckedPressed); break; case RadioButtonState.UncheckedDisabled: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.UncheckedDisabled); break; case RadioButtonState.UncheckedHot: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.UncheckedHot); break; case RadioButtonState.UncheckedPressed: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.UncheckedPressed); break; case RadioButtonState.UncheckedNormal: default: renderer = new VisualStyleRenderer(VisualStyleElement.Button.RadioButton.UncheckedNormal); break; } renderer.DrawBackground(g, checkRect, clipRect); } else { ControlPaint.DrawRadioButton(g, checkRect, ThemeManager.ConvertRadioButtonStateToButtonState(state)); } }
public static Size GetGlyphSize(Graphics g, RadioButtonState state) { if (RenderWithVisualStyles) { InitializeRenderer((int) state); return visualStyleRenderer.GetPartSize(g, ThemeSizeType.Draw); } return new Size(13, 13); }
public static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, RadioButtonState state) { Color controlText; Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state)); if (RenderWithVisualStyles) { InitializeRenderer((int) state); visualStyleRenderer.DrawImage(g, imageBounds, image); visualStyleRenderer.DrawBackground(g, bounds); controlText = visualStyleRenderer.GetColor(ColorProperty.TextColor); } else { g.DrawImage(image, imageBounds); ControlPaint.DrawRadioButton(g, bounds, ConvertToButtonState(state)); controlText = SystemColors.ControlText; } TextRenderer.DrawText(g, radioButtonText, font, textBounds, controlText, flags); if (focused) { ControlPaint.DrawFocusRectangle(g, textBounds); } }
// Main paiting method protected override void OnDrawItem(DrawItemEventArgs e) { int maxItem = this.Items.Count - 1; if (e.Index < 0 || e.Index > maxItem) { // Erase all background if control has no items e.Graphics.FillRectangle(BackBrush, this.ClientRectangle); return; } int size = e.Font.Height; // button size depends on font height, not on item height // Calculate bounds for background, if last item paint up to bottom of control Rectangle backRect = e.Bounds; if (e.Index == maxItem) { backRect.Height = this.ClientRectangle.Top + this.ClientRectangle.Height - e.Bounds.Top; } e.Graphics.FillRectangle(BackBrush, backRect); // Determines text color/brush Brush textBrush; bool isChecked = (e.State & DrawItemState.Selected) == DrawItemState.Selected; RadioButtonState state = isChecked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal; if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled) { textBrush = SystemBrushes.GrayText; state = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled; } else if ((e.State & DrawItemState.Grayed) == DrawItemState.Grayed) { textBrush = SystemBrushes.GrayText; state = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled; } else { textBrush = SystemBrushes.FromSystemColor(this.ForeColor); } // Determines bounds for text and radio button Size glyphSize = RadioButtonRenderer.GetGlyphSize(e.Graphics, state); Point glyphLocation = e.Bounds.Location; glyphLocation.Y += (e.Bounds.Height - glyphSize.Height) / 2; Rectangle bounds = new Rectangle(e.Bounds.X + glyphSize.Width, e.Bounds.Y, e.Bounds.Width - glyphSize.Width, e.Bounds.Height); // Draws the radio button RadioButtonRenderer.DrawRadioButton(e.Graphics, glyphLocation, state); // Draws the text if (!string.IsNullOrEmpty(DisplayMember)) // Bound Datatable? Then show the column written in Displaymember { e.Graphics.DrawString(((System.Data.DataRowView) this.Items[e.Index])[this.DisplayMember].ToString(), e.Font, textBrush, bounds, this.Align); } else { e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush, bounds, this.Align); } // If the ListBox has focus, draw a focus rectangle around the selected item. e.DrawFocusRectangle(); }
/// <summary> /// OnDrawItem /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index < 0) { return; } if (e.Index > this.Items.Count - 1) { return; } int size = e.Font.Height + 5; // button size depends on font height, not on item height if (IsTransparent && e.State != DrawItemState.Selected) { e.Graphics.FillRectangle(TransparentBrush, e.Bounds); } else { e.DrawBackground(); } Brush textBrush; bool isChecked = (e.State & DrawItemState.Selected) == DrawItemState.Selected; RadioButtonState state = isChecked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal; if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled) { textBrush = SystemBrushes.GrayText; state = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled; } else if ((e.State & DrawItemState.Grayed) == DrawItemState.Grayed) { textBrush = SystemBrushes.GrayText; state = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled; } else if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !Transparent) { textBrush = SystemBrushes.HighlightText; } else { textBrush = SystemBrushes.FromSystemColor(this.ForeColor); } // Draw radio button Rectangle bounds = e.Bounds; bounds.Height += 10; bounds.Width = size; RadioButtonRenderer.DrawRadioButton(e.Graphics, bounds.Location, state); // Draw text bounds = new Rectangle(e.Bounds.X + size + 2, e.Bounds.Y, e.Bounds.Width - size - 2, e.Bounds.Height); if (!string.IsNullOrEmpty(DisplayMember)) // Bound Datatable? Then show the column written in Displaymember { object item = this.Items[e.Index]; object subItem = base.FilterItemOnProperty(item, base.ValueMember); e.Graphics.DrawString(subItem.ToString(), e.Font, textBrush, bounds, this.Align); } else { e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush, bounds, this.Align); } // If the ListBox has focus, // draw a focus rectangle around the selected item. e.DrawFocusRectangle(); }
public static bool IsBackgroundPartiallyTransparent (RadioButtonState state) { if (!VisualStyleRenderer.IsSupported) return false; VisualStyleRenderer vsr = GetRadioButtonRenderer (state); return vsr.IsBackgroundPartiallyTransparent (); }
/// <summary> /// Converts the specified RadioButtonState value to a ButtonState value /// </summary> /// <param name="state">The RadioButtonState value to be converted</param> /// <returns>A ButtonState value that represents the specified RadioButtonState /// value</returns> private static ButtonState ConvertRadioButtonStateToButtonState(RadioButtonState state) { switch (state) { case RadioButtonState.UncheckedPressed: { return ButtonState.Pushed; } case RadioButtonState.UncheckedDisabled: { return ButtonState.Inactive; } case RadioButtonState.CheckedNormal: case RadioButtonState.CheckedHot: { return ButtonState.Checked; } case RadioButtonState.CheckedPressed: { return (ButtonState.Checked | ButtonState.Pushed); } case RadioButtonState.CheckedDisabled: { return (ButtonState.Checked | ButtonState.Inactive); } } return ButtonState.Normal; }
// Let the item paint itself, and then paint the RadioButton // where the check mark is displayed, covering the check mark // if it is present. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // If the client sets the Image property, the selection behavior // remains unchanged, but the RadioButton is not displayed and the // selection is indicated only by the selection rectangle. if (Image != null) { return; } // Determine the correct state of the RadioButton. RadioButtonState buttonState = RadioButtonState.UncheckedNormal; if (Enabled) { if (mouseDownState) { if (Checked) { buttonState = RadioButtonState.CheckedPressed; } else { buttonState = RadioButtonState.UncheckedPressed; } } else if (mouseHoverState) { if (Checked) { buttonState = RadioButtonState.CheckedHot; } else { buttonState = RadioButtonState.UncheckedHot; } } else { if (Checked) { buttonState = RadioButtonState.CheckedNormal; } } } else { if (Checked) { buttonState = RadioButtonState.CheckedDisabled; } else { buttonState = RadioButtonState.UncheckedDisabled; } } // Calculate the position at which to display the RadioButton. Int32 offset = (ContentRectangle.Height - RadioButtonRenderer.GetGlyphSize( e.Graphics, buttonState).Height) / 2; Point imageLocation = new Point( ContentRectangle.Location.X + 4, ContentRectangle.Location.Y + offset); // If the item is selected and the RadioButton paints with partial // transparency, such as when theming is enabled, the check mark // shows through the RadioButton image. In this case, paint a // non-transparent background first to cover the check mark. if (Checked && RadioButtonRenderer .IsBackgroundPartiallyTransparent(buttonState)) { Size glyphSize = RadioButtonRenderer .GetGlyphSize(e.Graphics, buttonState); glyphSize.Height--; glyphSize.Width--; Rectangle backgroundRectangle = new Rectangle(imageLocation, glyphSize); e.Graphics.FillEllipse( SystemBrushes.Control, backgroundRectangle); } RadioButtonRenderer.DrawRadioButton( e.Graphics, imageLocation, buttonState); }