/// <summary> /// Raises the PaintBackground event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> protected override void OnPaintBackground(PaintCellEventArgs e) { base.OnPaintBackground(e); // don't bother going any further if the Cell is null if (e.Cell == null) { return; } // get the button state ButtonRendererData rendererData = this.GetButtonRendererData(e.Cell); PushButtonStates state = rendererData.ButtonState; // if the cell has focus and is in its normal state, // make the button look like a default button if (state == PushButtonStates.Normal && e.Focused) { state = PushButtonStates.Default; } // if the table is not enabled, make sure the button is disabled if (!e.Enabled) { state = PushButtonStates.Disabled; } // draw the button ThemeManager.DrawButton(e.Graphics, this.CalcButtonBounds(), state); }
/// <summary> /// Draws a button control /// </summary> public override void DrawButton (System.Drawing.Graphics graphics, int x, int y, int width, int height, ButtonState state, System.Drawing.Color foreColor, System.Drawing.Color backColor, bool isDefault) { // revert to default theme if necessary if (!enableTheme) // && !FlatStyle.System { base.DrawButton(graphics, x, y, width, height, state, foreColor, backColor, isDefault); return; } PushButtonStates ctlState = PushButtonStates.PBS_NORMAL; #if DEBUG Console.WriteLine("DrawButton() state: {0:X}, default: {1}", state, isDefault); #endif if ((state & (ButtonState)0x20000) != 0) { ctlState = PushButtonStates.PBS_DEFAULTED; } else if ((state & ButtonState.Flat) != 0) { ctlState = PushButtonStates.PBS_HOT; } if ((state & ButtonState.Pushed) != 0) { ctlState = PushButtonStates.PBS_PRESSED; } Theme.DrawControl(graphics, "Button", x, y, width, height, (int)ButtonParts.BP_PUSHBUTTON, (int)ctlState); }
/// <summary> /// Draws a push 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 PushButtonStates value that specifies the /// state to draw the button in</param> public static void DrawButton(Graphics g, Rectangle buttonRect, Rectangle clipRect, PushButtonStates state) { if (g == null || buttonRect.Width <= 0 || buttonRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0) { return; } if (ThemeManager.VisualStylesEnabled) { ThemeManager.DrawThemeBackground(g, ThemeClasses.Button, (int) ButtonParts.PushButton, (int) state, buttonRect, clipRect); } else { ControlPaint.DrawButton(g, buttonRect, ThemeManager.ConvertPushButtonStateToButtonState(state)); } }
/// <summary> /// Converts the specified PushButtonStates value to a ButtonState value /// </summary> /// <param name="state">The PushButtonStates value to be converted</param> /// <returns>A ButtonState value that represents the specified PushButtonStates /// value</returns> private static ButtonState ConvertPushButtonStateToButtonState(PushButtonStates state) { switch (state) { case PushButtonStates.Pressed: { return(ButtonState.Pushed); } case PushButtonStates.Disabled: { return(ButtonState.Inactive); } } return(ButtonState.Normal); }
/// <summary> /// Draws a push 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="state">A PushButtonStates value that specifies the /// state to draw the button in</param> public static void DrawButton(Graphics g, Rectangle buttonRect, PushButtonStates state) { ThemeManager.DrawButton(g, buttonRect, buttonRect, state); }
/// <summary> /// Initializes a new instance of the ButtonRendererData class /// </summary> public ButtonRendererData() { this.buttonState = PushButtonStates.Normal; this.clickX = -1; this.clickY = -1; }
/// <summary> /// Converts the specified PushButtonStates value to a ButtonState value /// </summary> /// <param name="state">The PushButtonStates value to be converted</param> /// <returns>A ButtonState value that represents the specified PushButtonStates /// value</returns> private static ButtonState ConvertPushButtonStateToButtonState(PushButtonStates state) { switch (state) { case PushButtonStates.Pressed: { return ButtonState.Pushed; } case PushButtonStates.Disabled: { return ButtonState.Inactive; } } return ButtonState.Normal; }