public static void DrawDropDownButton (Graphics g, Rectangle bounds, ComboBoxState state) { if (!IsSupported) throw new InvalidOperationException (); GetComboRenderer (state).DrawBackground (g, bounds); }
private static void DrawBackground(Graphics g, Rectangle bounds, ComboBoxState state) { visualStyleRenderer.DrawBackground(g, bounds); if ((state != ComboBoxState.Disabled) && (visualStyleRenderer.GetColor(ColorProperty.FillColor) != SystemColors.Window)) { Rectangle backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); backgroundContentRectangle.Inflate(-2, -2); g.FillRectangle(SystemBrushes.Window, backgroundContentRectangle); } }
public static void DrawTextBox(Graphics g, Rectangle bounds, ComboBoxState state) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(TextBoxElement.ClassName, TextBoxElement.Part, (int)state); } else { visualStyleRenderer.SetParameters(TextBoxElement.ClassName, TextBoxElement.Part, (int)state); } DrawBackground(g, bounds, state); }
public static void DrawDropDownButton(Graphics g, Rectangle bounds, ComboBoxState state) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(ComboBoxElement.ClassName, ComboBoxElement.Part, (int) state); } else { visualStyleRenderer.SetParameters(ComboBoxElement.ClassName, ComboBoxElement.Part, (int) state); } visualStyleRenderer.DrawBackground(g, bounds); }
public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, TextFormatFlags flags, ComboBoxState state) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(TextBoxElement.ClassName, TextBoxElement.Part, (int) state); } else { visualStyleRenderer.SetParameters(TextBoxElement.ClassName, TextBoxElement.Part, (int) state); } Rectangle backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); backgroundContentRectangle.Inflate(-2, -2); DrawTextBox(g, bounds, comboBoxText, font, backgroundContentRectangle, flags, state); }
public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, TextFormatFlags flags, ComboBoxState state) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(TextBoxElement.ClassName, TextBoxElement.Part, (int) state); } else { visualStyleRenderer.SetParameters(TextBoxElement.ClassName, TextBoxElement.Part, (int) state); } DrawBackground(g, bounds, state); Color foreColor = visualStyleRenderer.GetColor(ColorProperty.TextColor); TextRenderer.DrawText(g, comboBoxText, font, textBounds, foreColor, flags); }
private static void DrawBackground(Graphics g, Rectangle bounds, ComboBoxState state) { visualStyleRenderer.DrawBackground(g, bounds); //for disabled comboboxes, comctl does not use the window backcolor, so // we don't refill here in that case. if (state != ComboBoxState.Disabled) { Color windowColor = visualStyleRenderer.GetColor(ColorProperty.FillColor); if (windowColor != SystemColors.Window) { Rectangle fillRect = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); fillRect.Inflate(-2, -2); //then we need to re-fill the background. g.FillRectangle(SystemBrushes.Window, fillRect); } } }
public static void DrawTextBox (Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, TextFormatFlags flags, ComboBoxState state) { if (!IsSupported) throw new InvalidOperationException (); GetTextBoxRenderer (state).DrawBackground (g, bounds); if (textBounds == Rectangle.Empty) textBounds = new Rectangle (bounds.Left + 3, bounds.Top, bounds.Width - 4, bounds.Height); if (comboBoxText != String.Empty) if (state == ComboBoxState.Disabled) TextRenderer.DrawText (g, comboBoxText, font, textBounds, SystemColors.GrayText, flags); else TextRenderer.DrawText (g, comboBoxText, font, textBounds, SystemColors.ControlText, flags); }
/// <include file='doc\ComboBoxRenderer.uex' path='docs/doc[@for="ComboBoxRenderer.DrawTextBox3"]/*' /> /// <devdoc> /// <para> /// Renders the textbox part of a ComboBox control. /// </para> /// </devdoc> public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, TextFormatFlags flags, ComboBoxState state) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(TextBoxElement.ClassName, TextBoxElement.Part, (int)state); } else { visualStyleRenderer.SetParameters(TextBoxElement.ClassName, TextBoxElement.Part, (int)state); } Rectangle textBounds = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); textBounds.Inflate(-2, -2); DrawTextBox(g, bounds, comboBoxText, font, textBounds, flags, state); }
/// <summary> /// Draws a combo box in the Windows Vista (and newer) style. /// </summary> /// <param name="graphics"></param> /// <param name="bounds"></param> /// <param name="state"></param> internal static void DrawComboBox(Graphics graphics, Rectangle bounds, ComboBoxState state) { Rectangle comboBounds = bounds; comboBounds.Inflate(1, 1); ButtonRenderer.DrawButton(graphics, comboBounds, GetPushButtonState(state)); Rectangle buttonBounds = new Rectangle( bounds.Left + (bounds.Width - 17), bounds.Top, 17, bounds.Height - (state != ComboBoxState.Pressed ? 1 : 0) ); Rectangle buttonClip = buttonBounds; buttonClip.Inflate(-2, -2); using (Region oldClip = graphics.Clip.Clone()) { graphics.SetClip(buttonClip, System.Drawing.Drawing2D.CombineMode.Intersect); ComboBoxRenderer.DrawDropDownButton(graphics, buttonBounds, state); graphics.SetClip(oldClip, System.Drawing.Drawing2D.CombineMode.Replace); } }
/// <summary> /// Initializes a new instance of the DropDownRendererData class /// </summary> public DropDownRendererData() { this.buttonState = ComboBoxState.Normal; this.clickX = -1; this.clickY = -1; }
public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, TextFormatFlags flags, ComboBoxState state) { if (!IsSupported) { throw new InvalidOperationException(); } GetTextBoxRenderer(state).DrawBackground(g, bounds); if (textBounds == Rectangle.Empty) { textBounds = new Rectangle(bounds.Left + 3, bounds.Top, bounds.Width - 4, bounds.Height); } if (comboBoxText != String.Empty) { if (state == ComboBoxState.Disabled) { TextRenderer.DrawText(g, comboBoxText, font, textBounds, SystemColors.GrayText, flags); } else { TextRenderer.DrawText(g, comboBoxText, font, textBounds, SystemColors.ControlText, flags); } } }
public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, TextFormatFlags flags, ComboBoxState state) { DrawTextBox(g, bounds, comboBoxText, font, Rectangle.Empty, flags |= TextFormatFlags.VerticalCenter, state); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (_ellipsis) { PushButtonState buttonState = PushButtonState.Normal; if (_mouseDown) { buttonState = PushButtonState.Pressed; } else if (_mouseOver) { buttonState = PushButtonState.Hot; } ButtonRenderer.DrawButton(g, new Rectangle(-1, -1, Width + 2, Height + 2), "…", Font, Focused, buttonState); } else { if (ComboBoxRenderer.IsSupported) { ComboBoxState state = ComboBoxState.Normal; if (Enabled) { if (_mouseDown) { state = ComboBoxState.Pressed; } else if (_mouseOver) { state = ComboBoxState.Hot; } } else { state = ComboBoxState.Disabled; } ComboBoxRenderer.DrawDropDownButton(g, new Rectangle(0, 0, Width, Height), state); } else { PushButtonState buttonState = PushButtonState.Normal; if (Enabled) { if (_mouseDown) { buttonState = PushButtonState.Pressed; } else if (_mouseOver) { buttonState = PushButtonState.Hot; } } else { buttonState = PushButtonState.Disabled; } ButtonRenderer.DrawButton(g, new Rectangle(-1, -1, Width + 2, Height + 2), string.Empty, Font, Focused, buttonState); // Draw the arrow icon try { Icon icon = new Icon(typeof(DesignerActionPanel), "Arrow.ico"); try { Bitmap arrowBitmap = icon.ToBitmap(); // Make sure we draw properly under high contrast by re-mapping // the arrow color to the WindowText color ImageAttributes attrs = new ImageAttributes(); try { ColorMap cm = new ColorMap { OldColor = Color.Black, NewColor = SystemColors.WindowText }; attrs.SetRemapTable(new ColorMap[] { cm }, ColorAdjustType.Bitmap); int imageWidth = arrowBitmap.Width; int imageHeight = arrowBitmap.Height; g.DrawImage(arrowBitmap, new Rectangle((Width - imageWidth + 1) / 2, (Height - imageHeight + 1) / 2, imageWidth, imageHeight), 0, 0, imageWidth, imageWidth, GraphicsUnit.Pixel, attrs, null, IntPtr.Zero); } finally { if (attrs != null) { attrs.Dispose(); } } } finally { if (icon != null) { icon.Dispose(); } } } catch { } } if (Focused) { ControlPaint.DrawFocusRectangle(g, new Rectangle(2, 2, Width - 5, Height - 5)); } } }
public static void DrawDropDownButton(Graphics g, Rectangle bounds, ComboBoxState state) { using var hdc = new DeviceContextHdcScope(g); DrawDropDownButtonForHandle(hdc, bounds, state, IntPtr.Zero); }
/// <summary> /// Paints the control. /// </summary> /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param> protected virtual void PaintControl(PaintEventArgs e) { var cbi = NativeMethods.COMBOBOXINFO.FromComboBox(this); string itemText = SelectedIndex >= 0 ? GetItemText(SelectedItem) : string.Empty; ComboBoxState state = Enabled ? currentState : ComboBoxState.Disabled; Rectangle tr = cbi.rcItem; /*Rectangle tr = this.ClientRectangle; * tr.Width -= (SystemInformation.VerticalScrollBarWidth + 2); * tr.Inflate(0, -2); * tr.Offset(1, 0);*/ Rectangle br = cbi.rcButton; bool vsSuccess = false; if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles) { /*Rectangle r = Rectangle.Inflate(this.ClientRectangle, 1, 1); * if (this.DropDownStyle != ComboBoxStyle.DropDownList) * { * e.Graphics.Clear(this.BackColor); * ComboBoxRenderer.DrawTextBox(e.Graphics, r, itemText, this.Font, tr, tff, state); * ComboBoxRenderer.DrawDropDownButton(e.Graphics, br, state); * } * else*/ { try { var vr = new VisualStyleRenderer("Combobox", DropDownStyle == ComboBoxStyle.DropDownList ? 5 : 4, (int)state); vr.DrawParentBackground(e.Graphics, ClientRectangle, this); vr.DrawBackground(e.Graphics, ClientRectangle); if (DropDownStyle != ComboBoxStyle.DropDownList) { br.Inflate(1, 1); } Rectangle cr = DropDownStyle == ComboBoxStyle.DropDownList ? Rectangle.Inflate(br, -1, -1) : br; vr.SetParameters("Combobox", 7, (int)(br.Contains(PointToClient(Cursor.Position)) ? state : ComboBoxState.Normal)); vr.DrawBackground(e.Graphics, br, cr); if (Focused && State != ComboBoxState.Pressed) { Size sz = TextRenderer.MeasureText(e.Graphics, "Wg", Font, tr.Size, TextFormatFlags.Default); Rectangle fr = Rectangle.Inflate(tr, 0, ((sz.Height - tr.Height) / 2) + 1); ControlPaint.DrawFocusRectangle(e.Graphics, fr); } TextRenderer.DrawText(e.Graphics, itemText, Font, tr, ForeColor, tff); vsSuccess = true; } catch { } } } if (!vsSuccess) { System.Diagnostics.Debug.WriteLine($"CR:{ClientRectangle};ClR:{e.ClipRectangle};Foc:{Focused};St:{state};Tx:{itemText}"); var bgc = Enabled ? BackColor : SystemColors.Control; e.Graphics.Clear(bgc); ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken); ControlPaint.DrawComboButton(e.Graphics, br, Enabled ? (state == ComboBoxState.Pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive); //using (var bb = new SolidBrush(this.BackColor)) // e.Graphics.FillRectangle(bb, tr); if (Focused) { Size sz = TextRenderer.MeasureText(e.Graphics, "Wg", Font, tr.Size, TextFormatFlags.Default); Rectangle fr = Rectangle.Inflate(tr, 0, ((sz.Height - tr.Height) / 2) + 1); e.Graphics.FillRectangle(SystemBrushes.Highlight, fr); ControlPaint.DrawFocusRectangle(e.Graphics, fr); //, this.ForeColor, SystemColors.Highlight); } TextRenderer.DrawText(e.Graphics, itemText, Font, tr, Focused ? SystemColors.HighlightText : (Enabled ? ForeColor : SystemColors.GrayText), bgc, tff); } }
public static void Initialize() { Command command = Command.Create(commandName); command.ControlState = ComboBoxState.CreateFixed(names.Values.ToArray(), 0); }
private static VisualStyleRenderer GetTextBoxRenderer (ComboBoxState state) { switch (state) { case ComboBoxState.Disabled: return new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Disabled); case ComboBoxState.Hot: return new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Hot); case ComboBoxState.Normal: case ComboBoxState.Pressed: default: return new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Normal); } }
/// <summary> /// Initializes a new instance of the DropDownRendererData class /// </summary> public DropDownRendererData() { this.buttonState = ComboBoxState.Normal; this.clickX = -1; this.clickY = -1; }
public static void DrawDropDownButton(Graphics g, Rectangle bounds, ComboBoxState state) { DrawDropDownButtonForHandle(g, bounds, state, IntPtr.Zero); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (BufferedPaintSupported) { var stateChanged = !Equals(currentState, newState); using (var hdc = new SafeGDIHandle(e.Graphics)) { if (hdc.IsInvalid || NativeMethods.BufferedPaintRenderAnimation(Handle, hdc)) { return; } var animParams = new NativeMethods.BufferedPaintAnimationParams(NativeMethods.BufferedPaintAnimationStyle.Linear); // get appropriate animation time depending on state transition (or 0 if unchanged) if (stateChanged) { foreach (var item in transitions) { if (item.currentState == currentState && item.newState == newState) { animParams.Duration = item.duration; break; } } } var rc = ClientRectangle; IntPtr hdcFrom, hdcTo; var hbpAnimation = NativeMethods.BeginBufferedAnimation(Handle, hdc, ref rc, NativeMethods.BufferedPaintBufferFormat.CompatibleBitmap, IntPtr.Zero, ref animParams, out hdcFrom, out hdcTo); if (hbpAnimation != IntPtr.Zero) { if (hdcFrom != IntPtr.Zero) { using (var gfxFrom = Graphics.FromHdc(hdcFrom)) PaintControl(new PaintEventArgs(gfxFrom, e.ClipRectangle)); } currentState = newState; if (hdcTo != IntPtr.Zero) { using (var gfxTo = Graphics.FromHdc(hdcTo)) PaintControl(new PaintEventArgs(gfxTo, e.ClipRectangle)); } NativeMethods.EndBufferedAnimation(hbpAnimation, true); } else { hdc.Dispose(); currentState = newState; PaintControl(e); } } } else { // buffered painting not supported, just paint using the current state currentState = newState; PaintControl(e); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.MouseEnter" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); State = ComboBoxState.Hot; }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.MouseDown" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); State = ComboBoxState.Pressed; }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.ComboBox.DropDownClosed" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnDropDownClosed(EventArgs e) { base.OnDropDownClosed(e); State = ComboBoxState.Normal; }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.ComboBox.DropDown" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnDropDown(EventArgs e) { base.OnDropDown(e); State = ComboBoxState.Pressed; }
public static void DrawTextBox (Graphics g, Rectangle bounds, ComboBoxState state) { DrawTextBox (g, bounds, String.Empty, null, Rectangle.Empty, TextFormatFlags.VerticalCenter, state); }
public static void DrawDropDownButton(Graphics g, Rectangle controlBounds, Rectangle buttonBounds, ComboBoxState state, Color buttonColor, Color triangleColor) { var dropButtonBrush = new SolidBrush(buttonColor); g.FillRectangle(dropButtonBrush, buttonBounds); var TopLeft = new PointF(controlBounds.Width - 20, (controlBounds.Height - 7) / 2); var TopRight = new PointF(controlBounds.Width - 10, (controlBounds.Height - 7) / 2); var Bottom = new PointF(controlBounds.Width - 15, (controlBounds.Height + 3) / 2); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; var arrowBrush = new SolidBrush(triangleColor); g.FillRectangle(dropButtonBrush, buttonBounds); g.FillPolygon(arrowBrush, new PointF[] { TopLeft, TopRight, Bottom }); }
public static void DrawTextBox (Graphics g, Rectangle bounds, string comboBoxText, Font font, TextFormatFlags flags, ComboBoxState state) { DrawTextBox (g, bounds, comboBoxText, font, Rectangle.Empty, flags |= TextFormatFlags.VerticalCenter, state); }
public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, TextFormatFlags flags, ComboBoxState state) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(TextBoxElement.ClassName, TextBoxElement.Part, (int)state); } else { visualStyleRenderer.SetParameters(TextBoxElement.ClassName, TextBoxElement.Part, (int)state); } DrawBackground(g, bounds, state); Color textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor); TextRenderer.DrawText(g, comboBoxText, font, textBounds, textColor, flags); }
private static VisualStyleRenderer GetComboRenderer (ComboBoxState state) { switch (state) { case ComboBoxState.Disabled: return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Disabled); case ComboBoxState.Hot: return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Hot); case ComboBoxState.Normal: default: return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Normal); case ComboBoxState.Pressed: return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Pressed); } }
internal static void DrawDropDownButtonForHandle(Gdi32.HDC hdc, Rectangle bounds, ComboBoxState state, IntPtr handle) { if (visualStyleRenderer == null) { visualStyleRenderer = new VisualStyleRenderer(ComboBoxElement.ClassName, ComboBoxElement.Part, (int)state); } else { visualStyleRenderer.SetParameters(ComboBoxElement.ClassName, ComboBoxElement.Part, (int)state); } visualStyleRenderer.DrawBackground(hdc, bounds, handle); }
/// <summary> /// Paints the column header cell, including the drop-down button. /// </summary> /// <param name="graphics">The Graphics used to paint the DataGridViewCell.</param> /// <param name="clipBounds">A Rectangle that represents the area of the DataGridView that needs to be repainted.</param> /// <param name="cellBounds">A Rectangle that contains the bounds of the DataGridViewCell that is being painted.</param> /// <param name="rowIndex">The row index of the cell that is being painted.</param> /// <param name="cellState">A bitwise combination of DataGridViewElementStates values that specifies the state of the cell.</param> /// <param name="value">The data of the DataGridViewCell that is being painted.</param> /// <param name="formattedValue">The formatted data of the DataGridViewCell that is being painted.</param> /// <param name="errorText">An error message that is associated with the cell.</param> /// <param name="cellStyle">A DataGridViewCellStyle that contains formatting and style information about the cell.</param> /// <param name="advancedBorderStyle">A DataGridViewAdvancedBorderStyle that contains border styles for the cell that is being painted.</param> /// <param name="paintParts">A bitwise combination of the DataGridViewPaintParts values that specifies which parts of the cell need to be painted.</param> protected override void Paint(System.Drawing.Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); // Continue only if the drop down is to be visible and ContentBackground is part of the paint request. if (!this.IsProgrammaticSorting || (paintParts & DataGridViewPaintParts.ContentBackground) == 0) { return; } Rectangle buttonBounds = this.DropDownButtonBounds; if (buttonBounds.Width > 0 && buttonBounds.Height > 0) // make sure there's something to draw... { // Paint the button manually or using visual styles if visual styles // are enabled, using the correct state depending on whether the // filter list is showing and whether there is a filter in effect // for the current column. if (Application.RenderWithVisualStyles) { ComboBoxState state = ComboBoxState.Normal; if (!this.DropDownEnabled) { state = ComboBoxState.Disabled; } else if (this.IsDropDownShowing) { state = ComboBoxState.Pressed; } ComboBoxRenderer.DrawDropDownButton(graphics, buttonBounds, state); } else { int pressedOffset = 0; PushButtonState state = PushButtonState.Normal; if (!this.DropDownEnabled) { state = PushButtonState.Disabled; } else if (this.IsDropDownShowing) { state = PushButtonState.Pressed; pressedOffset = 1; } ButtonRenderer.DrawButton(graphics, buttonBounds, state); graphics.FillPolygon(this.DropDownEnabled ? SystemBrushes.ControlText : SystemBrushes.InactiveCaption, new Point[] { new Point( buttonBounds.Width / 2 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height * 3 / 4 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width / 4 + buttonBounds.Left + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width * 3 / 4 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset) }); } // and then paint a filtering and/or sorting glyph if (_filtered) { Bitmap glyph = Properties.Resources.FilterHeaderCellGlyph; Rectangle cbb = this.DataGridView.GetCellDisplayRectangle(this.ColumnIndex, -1, false); graphics.DrawImage(glyph, new Rectangle(buttonBounds.Left - glyph.Width - 3, (cbb.Height - glyph.Height) / 2, glyph.Width, glyph.Height)); } } }
public static void DrawTextBox(Graphics g, Rectangle bounds, ComboBoxState state) { DrawTextBox(g, bounds, String.Empty, null, Rectangle.Empty, TextFormatFlags.VerticalCenter, state); }
/// <summary> /// Draws a combobox button 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="buttonRect">The Rectangle that represents the dimensions /// of the button</param> /// <param name="clipRect">The Rectangle that represents the clipping area</param> /// <param name="state">A ComboBoxState value that specifies the /// state to draw the combobox button in</param> public static void DrawComboBoxButton(Graphics g, Rectangle buttonRect, Rectangle clipRect, ComboBoxState state) { if (g == null || buttonRect.Width <= 0 || buttonRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0) { return; } if (ThemeManager.VisualStylesEnabled) { //ThemeManager.DrawThemeBackground(g, ThemeClasses.ComboBox, (int) ComboBoxParts.DropDownButton, (int) state, buttonRect, clipRect); VisualStyleRenderer renderer; switch (state) { case ComboBoxState.Disabled: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Disabled); break; case ComboBoxState.Hot: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Hot); break; case ComboBoxState.Pressed: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Pressed); break; case ComboBoxState.Normal: default: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Normal); break; } renderer.DrawBackground(g, buttonRect, clipRect); } else { ControlPaint.DrawComboButton(g, buttonRect, ThemeManager.ConvertComboBoxStateToButtonState(state)); } }
/// <summary> /// Converts a ComboBoxState into its equivalent PushButtonState value. /// </summary> /// <param name="combo"></param> /// <returns></returns> static PushButtonState GetPushButtonState(ComboBoxState combo) { switch (combo) { case ComboBoxState.Disabled: return PushButtonState.Disabled; case ComboBoxState.Hot: return PushButtonState.Hot; case ComboBoxState.Pressed: return PushButtonState.Pressed; default: return PushButtonState.Normal; } }
/// <summary> /// Draws a combobox button 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="buttonRect">The Rectangle that represents the dimensions /// of the combobox button</param> /// <param name="state">A ComboBoxState value that specifies the /// state to draw the combobox button in</param> public static void DrawComboBoxButton(Graphics g, Rectangle buttonRect, ComboBoxState state) { ThemeManager.DrawComboBoxButton(g, buttonRect, buttonRect, state); }
protected override void Paint( Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Use the base method to paint the default appearance. base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); // Continue only if filtering is enabled and ContentBackground is // part of the paint request. if (!FilteringEnabled || (paintParts & DataGridViewPaintParts.ContentBackground) == 0) { return; } // Retrieve the current button bounds. Rectangle buttonBounds = DropDownButtonBounds; // Continue only if the buttonBounds is big enough to draw. if (buttonBounds.Width < 1 || buttonBounds.Height < 1) { return; } // Paint the button manually or using visual styles if visual styles // are enabled, using the correct state depending on whether the // filter list is showing and whether there is a filter in effect // for the current column. if (Application.RenderWithVisualStyles) { ComboBoxState state = ComboBoxState.Normal; if (dropDownListBoxShowing) { state = ComboBoxState.Pressed; } else if (CheckFiltered()) { state = ComboBoxState.Hot; } ComboBoxRenderer.DrawDropDownButton( graphics, buttonBounds, state); } else { // Determine the pressed state in order to paint the button // correctly and to offset the down arrow. Int32 pressedOffset = 0; PushButtonState state = PushButtonState.Normal; if (dropDownListBoxShowing) { state = PushButtonState.Pressed; pressedOffset = 1; } ButtonRenderer.DrawButton(graphics, buttonBounds, state); // If there is a filter in effect for the column, paint the // down arrow as an unfilled triangle. If there is no filter // in effect, paint the down arrow as a filled triangle. if (CheckFiltered()) { graphics.DrawPolygon(SystemPens.ControlText, new Point[] { new Point( buttonBounds.Width / 2 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height * 3 / 4 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width / 4 + buttonBounds.Left + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width * 3 / 4 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset) }); } else { graphics.FillPolygon(SystemBrushes.ControlText, new Point[] { new Point( buttonBounds.Width / 2 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height * 3 / 4 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width / 4 + buttonBounds.Left + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width * 3 / 4 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset) }); } } }
/// <summary> /// Converts a ComboBoxState value into its equivalent PushButtonState value. /// </summary> /// <param name="state"></param> /// <returns></returns> private PushButtonState GetPushButtonState(ComboBoxState state) { switch (state) { case ComboBoxState.Disabled: return PushButtonState.Disabled; case ComboBoxState.Hot: return PushButtonState.Hot; case ComboBoxState.Pressed: return PushButtonState.Pressed; } return PushButtonState.Normal; }
/// <include file='doc\ComboBoxRenderer.uex' path='docs/doc[@for="ComboBoxRenderer.DrawTextBox2"]/*' /> /// <devdoc> /// <para> /// Renders the textbox part of a ComboBox control. /// </para> /// </devdoc> public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, ComboBoxState state) { DrawTextBox(g, bounds, comboBoxText, font, textBounds, TextFormatFlags.TextBoxControl, state); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // Check whether the user clicked the arrow. if (arrowRectangle.Contains(e.Location) && ComboBoxRenderer.IsSupported) { // Draw the arrow in the pressed state. arrowState = ComboBoxState.Pressed; // The user has activated the combo box. if (!isActivated) { this.Text = "Clicked!"; textBoxState = ComboBoxState.Pressed; isActivated = true; } // The user has deactivated the combo box. else { this.Text = "Click here"; textBoxState = ComboBoxState.Normal; isActivated = false; } // Redraw the control. Invalidate(); } }
public static void DrawDropDownButton(Graphics g, Rectangle bounds, ComboBoxState state) { ComboBoxRenderer.DrawDropDownButton(g, bounds, state); }
/// <summary> /// Draws a combobox button 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="buttonRect">The Rectangle that represents the dimensions /// of the button</param> /// <param name="clipRect">The Rectangle that represents the clipping area</param> /// <param name="state">A ComboBoxState value that specifies the /// state to draw the combobox button in</param> public static void DrawComboBoxButton(Graphics g, Rectangle buttonRect, Rectangle clipRect, ComboBoxState state) { if (g == null || buttonRect.Width <= 0 || buttonRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0) { return; } if (ThemeManager.VisualStylesEnabled) { //ThemeManager.DrawThemeBackground(g, ThemeClasses.ComboBox, (int) ComboBoxParts.DropDownButton, (int) state, buttonRect, clipRect); VisualStyleRenderer renderer; switch (state) { case ComboBoxState.Disabled: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Disabled); break; case ComboBoxState.Hot: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Hot); break; case ComboBoxState.Pressed: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Pressed); break; case ComboBoxState.Normal: default: renderer = new VisualStyleRenderer(VisualStyleElement.ComboBox.DropDownButton.Normal); break; } renderer.DrawBackground(g, buttonRect, clipRect); } else { ControlPaint.DrawComboButton(g, buttonRect, ThemeManager.ConvertComboBoxStateToButtonState(state)); } }
/// <include file='doc\ComboBoxRenderer.uex' path='docs/doc[@for="ComboBoxRenderer.DrawTextBox2"]/*' /> /// <devdoc> /// <para> /// Renders the textbox part of a ComboBox control. /// </para> /// </devdoc> public static void DrawTextBox(Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, ComboBoxState state) { DrawTextBox(g, bounds, comboBoxText, font, textBounds, TextFormatFlags.TextBoxControl, state); }
private static void DrawDropDownButton(IDeviceContext g, Rectangle bounds, ComboBoxState state, ComboBoxElementParts part = ComboBoxElementParts.DropDownButton) { var visualStyleRenderer = new VisualStyleRenderer("COMBOBOX", (int)part, (int)state); visualStyleRenderer.DrawBackground(g, bounds); }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (arrowRectangle.Contains(e.Location) && ComboBoxRenderer.IsSupported) { arrowState = ComboBoxState.Normal; Invalidate(); } }
public static void DrawTextBox(Graphics g, Rectangle bounds, ComboBoxState state) { ComboBoxRenderer.DrawTextBox(g, bounds, state); }
public static void DrawTextBox(Graphics g, Rectangle bounds, ComboBoxState state) { ComboBoxRenderer.DrawTextBox(g, bounds, state); }
public static void DrawDropDownButton(Graphics g, Rectangle bounds, ComboBoxState state) { ComboBoxRenderer.DrawDropDownButton(g, bounds, state); }
/// <summary> /// Draws a combobox button 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="buttonRect">The Rectangle that represents the dimensions /// of the combobox button</param> /// <param name="state">A ComboBoxState value that specifies the /// state to draw the combobox button in</param> public static void DrawComboBoxButton(Graphics g, Rectangle buttonRect, ComboBoxState state) { ThemeManager.DrawComboBoxButton(g, buttonRect, buttonRect, state); }
/// <summary> /// 绘制列标题单元格,包括下拉按钮。 /// </summary> /// <param name="graphics">用于绘制 DataGridViewCell 的图形。</param> /// <param name="clipBounds">表示需要重新绘制的 DataGridView 区域的矩形。</param> /// <param name="cellBounds">包含正在绘制的数据网格查看单元边界的矩形。</param> /// <param name="rowIndex">正在绘制的单元格的行索引。</param> /// <param name="cellState">DataGridViewElement 的位值,用于指定单元格的状态。</param> /// <param name="value">正在绘制的数据网格查看单元的数据.</param> /// <param name="formattedValue">正在绘制的 DataGridViewCell 的格式化数据.</param> /// <param name="errorText">与单元格关联的错误消息。</param> /// <param name="cellStyle">包含有关单元格的格式和样式信息的 DataGridViewCellStyle.</param> /// <param name="advancedBorderStyle">数据网格视图、行车边界样式,其中包含正在绘制的单元格的边框样式。</param> /// <param name="paintParts">DataGridViewPaintParts 值的位向组合,指定需要绘制单元格的哪些部分。</param> protected override void Paint( Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // 使用基方法绘制默认外观。 base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); //仅启用筛选且内容背景是绘制请求的一部分时才继续。 if (!FilteringEnabled || (paintParts & DataGridViewPaintParts.ContentBackground) == 0) { return; } // 检索当前按钮边界。 Rectangle buttonBounds = DropDownButtonBounds; // 仅当按钮"边界"足够大以进行绘制时,才继续。 if (buttonBounds.Width < 1 || buttonBounds.Height < 1) { return; } //如果启用了视觉样式, //则手动绘制按钮或使用视觉样式,使用正确的状态,具体取决于筛选器列表是否显示, //以及是否有过滤器有效当前列。 if (Application.RenderWithVisualStyles) { ComboBoxState state = ComboBoxState.Normal; if (filtered) { state = ComboBoxState.Hot; } ComboBoxRenderer.DrawDropDownButton( graphics, buttonBounds, state); } else { //确定按下状态,以便正确绘制按钮并偏移向下箭头。 Int32 pressedOffset = 0; PushButtonState state = PushButtonState.Normal; ButtonRenderer.DrawButton(graphics, buttonBounds, state); //如果列有有效的筛选器,请将向下箭头绘制为未填充的三角形。如果没有有效滤镜,请将向下箭头绘制为填充三角形。 if (filtered) { graphics.DrawPolygon(SystemPens.ControlText, new Point[] { new Point( buttonBounds.Width / 2 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height * 3 / 4 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width / 4 + buttonBounds.Left + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width * 3 / 4 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset) }); } else { graphics.FillPolygon(SystemBrushes.ControlText, new Point[] { new Point( buttonBounds.Width / 2 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height * 3 / 4 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width / 4 + buttonBounds.Left + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset), new Point( buttonBounds.Width * 3 / 4 + buttonBounds.Left - 1 + pressedOffset, buttonBounds.Height / 2 + buttonBounds.Top - 1 + pressedOffset) }); } } }
/// <summary> /// Converts the specified ComboBoxState value to a ButtonState value /// </summary> /// <param name="state">The ComboBoxState value to be converted</param> /// <returns>A ButtonState value that represents the specified ComboBoxState /// value</returns> private static ButtonState ConvertComboBoxStateToButtonState(ComboBoxState state) { switch (state) { case ComboBoxState.Pressed: { return ButtonState.Pushed; } case ComboBoxState.Disabled: { return ButtonState.Inactive; } } return ButtonState.Normal; }
internal static VisualStyleRenderer CreateRenderer(ComboBoxState state, bool useVisualStyleBackColor, bool readOnly, bool focused, bool hasBorder) { if (!Application.RenderWithVisualStyles) return null; VisualStyleElement element = null; if (readOnly && useVisualStyleBackColor) element = VisualStyleElement.CreateElement(COMBOBOX_CLASS, CP_READONLY, (int)state); if (element != null && VisualStyleRenderer.IsElementDefined(element)) return new VisualStyleRenderer(element); if (!hasBorder) return null; if (focused) { element = VisualStyleElement.CreateElement(COMBOBOX_CLASS, CP_BORDER, CBB_FOCUSED); if (!VisualStyleRenderer.IsElementDefined(element)) element = VisualStyleElement.TextBox.TextEdit.Focused; } else { switch (state) { case ComboBoxState.Normal: element = VisualStyleElement.CreateElement(COMBOBOX_CLASS, CP_BORDER, CBB_NORMAL); if (!VisualStyleRenderer.IsElementDefined(element)) element = VisualStyleElement.TextBox.TextEdit.Normal; break; case ComboBoxState.Hot: element = VisualStyleElement.CreateElement(COMBOBOX_CLASS, CP_BORDER, CBB_HOT); if (!VisualStyleRenderer.IsElementDefined(element)) element = VisualStyleElement.TextBox.TextEdit.Hot; break; case ComboBoxState.Pressed: element = VisualStyleElement.CreateElement(COMBOBOX_CLASS, CP_BORDER, CBB_HOT); if (!VisualStyleRenderer.IsElementDefined(element)) element = VisualStyleElement.TextBox.TextEdit.Hot; break; case ComboBoxState.Disabled: element = VisualStyleElement.CreateElement(COMBOBOX_CLASS, CP_BORDER, CBB_DISABLED); if (!VisualStyleRenderer.IsElementDefined(element)) element = VisualStyleElement.TextBox.TextEdit.Disabled; break; } } return new VisualStyleRenderer(element); }